My Favorite Git Commands

Git and GitHub are pretty much a part of a developer’s work day, and each developer tends to define their set of tried and true Git commands. Here is my list of Git commands (in no special order):

  1. git init: initialize a repository
  2. git branch -a: see all branches, including active branches
  3. git status: see the status of the active branch (and read hints for the next steps or fixing errors)
  4. git checkout <BRANCH> | <COMMIMT_ID>: activates branch or detaches head to commit in the current branch
  5. git show <COMMIT_ID>: show commit information (or add the --stat option for a short summary)
  6. git diff --name-only <BRANCH_X>..<BRANCH_Y>: see the difference between branch X and branch Y
  7. git commit -am "Commit message here": commit working tree by adding and message all in one
  8. git merge <BRANCH>: merge the branch into the current working tree
  9. git log --oneline --all: see the short commit history of all branches
  10. git diff-tree --no-commit-id --name-only -r <COMMIT_ID>: see files from the commit
  11. git reset --mixed <COMMIT_ID>: reset repository to commit, but keep indexed and untracked changes
  12. git reset --hard <COMMIT_ID>: reset repository to commit wiping out all working tree changes
  13. git remote --verbose: show remote repository
  14. git rm --cached <file_name>: remove the specified file from Git tracking
  15. git clean -f | -df: remove untracked files or untracked directories
  16. git branch -d -r <REMOTE>/<BRANCH>: remove the upstream branch in a local clone
  17. git remote prune <REMOTE>: removes references to remote branches that no longer exist
  18. git push -u <REMOTE> <BRANCH>: push the local branch to the remote

Well, there you have it. I’ll be adding/editing as necessary.