19 Tips For Everyday Git Use

I’ve been using git full time for the past 4 years, and I wanted to share the most practical tips that I’ve learned along the way. Hopefully, it will be useful to somebody out there.

If you are completely new to git, I suggest reading Git Cheat Sheet first. This article is aimed at somebody who has been using git for three months or more.

Table of Contexts:

  1. Parameters for better logging
    git log --oneline --graph
  2. Log actual changes in a file
    git log -p filename
  3. Only Log changes for some specific lines in file
    git log -L 1,1:some-file.txt
  4. Log changes not yet merged to the parent branch
    git log --no-merges master..
  5. Extract a file from another branch
    git show some-branch:some-file.js
  6. Some notes on rebasing
    git pull --rebase
  7. Remember the branch structure after a local merge
    git merge --no-ff
  8. Fix your previous commit, instead of making a new commit
    git commit --amend
  9. Three stages in git, and how to move between them
    git reset --hard HEAD and git status -s
  10. Revert a commit, softly
    git revert -n
  11. See diff-erence for the entire project (not just one file at a time) in a 3rd party diff tool
    git difftool -d
  12. Ignore the white space
    git diff -w
  13. Only “add” some changes from a file
    git add -p
  14. Discover and zap those old branches
    git branch -a
  15. Stash only some files
    git stash -p
  16. Good commit messages
  17. Git Auto-completion
  18. Create aliases for your most frequently used commands
  19. Quickly find a commit that broke your feature (EXTRA AWESOME)
    git bisect

Source: 19 Tips For Everyday Git Use