Allison is coding...

Notes|A List of Basic Git Commands

A list of essential Git commands that are commonly used for version control and collaboration:

Basic Git Commands

  1. Initialize a repository:

    • git init
      • Creates a new Git repository in your project directory.
  2. Clone a repository:

    • git clone [repository URL]
      • Copies an existing repository to your local machine.
  3. Check the status:

    • git status
      • Shows the status of your working directory and staging area (e.g., changes, staged files).
  4. Add files to staging:

    • git add [file]
      • Stages a specific file.
    • git add .
      • Stages all changes in the current directory.
  5. Commit changes:

    • git commit -m "[message]"
      • Records staged changes with a commit message.
  6. View commit history:

    • git log
      • Displays the commit history.
  7. Branching:

    • git branch
      • Lists branches in the repository.
    • git branch [branch_name]
      • Creates a new branch.
  8. Switch branches:

    • git checkout [branch_name]
      • Switches to the specified branch.
    • git switch [branch_name] (modern alternative)
      • Switches branches.
  9. Merge branches:

    • git merge [branch_name]
      • Merges the specified branch into the current branch.
  10. Push changes to a remote repository:

    • git push [remote] [branch]
      • Pushes changes to a specific branch in the remote repository.
  11. Pull changes from a remote repository:

    • git pull
      • Fetches and integrates changes from the remote repository into the current branch.
  12. Discard changes:

    • git checkout -- [file]
      • Discards changes in the working directory (reverts to the last committed state).
    • git reset --hard
      • Resets the staging area and working directory to the last commit.
  13. Stash changes:

    • git stash
      • Temporarily stores changes not ready to commit.
    • git stash apply
      • Restores the stashed changes.
  14. View differences:

    • git diff
      • Shows differences between changes in the working directory and the staged area.
  15. Remove files:

    • git rm [file]
      • Removes a file from the working directory and stages its deletion.
  16. Tagging:

    • git tag [tag_name]
      • Creates a tag for a specific commit.