The Ultimate Git Command List: 50 Must-Know Commands for Developers

The Ultimate Git Command List: 50 Must-Know Commands for Developers


Here are 50 Git commands that are commonly used in various stages of version control workflow:

Basic Commands

  1. git init - Initialize a new Git repository
  2. git clone [url] - Clone a repository into a new directory
  3. git add [file] - Add a file to the staging area
  4. git commit -m "[message]" - Commit changes to the repository with a message
  5. git status - Show the working tree status
  6. git branch - List, create, or delete branches
  7. git checkout [branch] - Switch to a specified branch
  8. git merge [branch] - Merge a branch into the active branch
  9. git pull [remote] [branch] - Pull changes from a remote repository
  10. git push [remote] [branch] - Push changes to a remote repository

Advanced Branching & Merging

  1. git branch -d [branch] - Delete a branch
  2. git checkout -b [branch] - Create and switch to a new branch
  3. git merge --no-ff [branch] - Merge with a commit even if fast-forward is possible
  4. git stash - Stash changes in a dirty working directory
  5. git stash pop - Apply stashed changes back to the working directory

Inspection and Comparison

  1. git log - Show commit logs
  2. git log --follow [file] - Show the commits that changed file
  3. git diff - Show changes between commits, commit and working tree, etc.
  4. git diff --staged - Show changes between the staging area and the latest commit
  5. git show [commit] - Show various types of objects

Undoing Changes

  1. git reset [file] - Unstage a file while retaining the changes in working directory
  2. git reset --hard [commit] - Reset the staging area and working directory to a specific commit
  3. git revert [commit] - Revert some existing commits
  4. git rm [file] - Remove files from the working tree and the index

Working with Remotes

  1. git remote - Manage set of tracked repositories
  2. git remote add [remote] [url] - Add a new remote
  3. git fetch [remote] - Download objects and refs from another repository
  4. git push [remote] [branch] - Update remote refs along with associated objects
  5. git pull - Fetch from and integrate with another repository or a local branch

Temporary Commits

  1. git stash - Stash the changes in a dirty working directory
  2. git stash list - List stack-order of stashed file changes
  3. git stash drop - Remove a single stashed state from the stash list
  4. git stash clear - Remove all the stashed states

Tagging

  1. git tag - List, create, delete or verify a tag object signed with GPG
  2. git tag -a [tag] -m [message] - Create an annotated tag
  3. git push [remote] [tag] - Share a tag

Git Configurations

  1. git config --global user.name "[name]" - Define the author name to be used for all commits in the current repo.
  2. git config --global user.email "[email address]" - Define the author email to be used for all commits in the current repo.

Patching

  1. git apply [patch] - Apply a patch to files and/or to the index
  2. git cherry-pick [commit] - Apply the changes introduced by some existing commits

Searching

  1. git grep [string] - Search for a string in the tracked files
  2. git bisect - Use binary search to find the commit that introduced a bug

Submodules

  1. git submodule add [url] [path] - Add a new submodule
  2. git submodule init - Initialize a submodule
  3. git submodule update - Update the submodules

Advanced Git

  1. git rebase [branch] - Reapply commits on top of another base tip
  2. git rebase --interactive - Perform an interactive rebase
  3. git filter-branch - Rewrite branches

Other

  1. git archive - Create an archive of files from a named tree
  2. git gc - Cleanup unnecessary files and optimize the local repository

These commands cover a wide range of Git functionalities, from basic setup and daily usage to more advanced features like branching, merging, and handling remote repositories.