Good Git!
Most used (but yet unremembered) git commands
TLDR;
1 | gl #git log --oneline --decorate --graph --all |
Push your currently detached HEAD
git push origin HEAD:master
Delete remote branches only
git push origin --delete branch_to_delete
Changes in git index vs. local filesystem
1 | git commit -m "Something terribly misguided" |
git reset --soft HEAD~1
doesn’t remove the changes from index (i.e.git commit
adds them again, no need to git add.).git reset HEAD~1
undoes the commit, removes changes from index but keeps the changes locally (working tree)git reset --hard HEAD~1
removes the changes from the filesystem (working tree) too.
Remove git tracked files without removing them from filesystem
git rm --cached --force ".idea"
Specific Usecases
Patch related
1 | #To see diff for a particular commit https://stackoverflow.com/a/17563740/1233476 |
Submodules
1 | #to checkout already existing submodules in an existing project |
Tags
1 | npm version patch/minor/major #Changes packages.json and applies git tag |
More awesome references:
- How to use git: https://guides.github.com/activities/contributing-to-open-source/#contributing
- How to write git commit messages: http://chris.beams.io/posts/git-commit/
- Commit guidelines: http://contribute.jquery.org/commits-and-pull-requests/#commit-guidelines
- Git reset/revert: https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting/
- Easy git rebase: http://hackalyst.info/easy-git-rebase/
- Real git rebase: http://hackalyst.info/real-rebase/
- A few git tricks: http://prakhar.me/articles/a-few-git-tricks/
- Working with submodules: https://github.com/blog/2104-working-with-submodules , https://chrisjean.com/git-submodules-adding-using-removing-and-updating/
- Another way of using git shortcuts (without using aliases): https://medium.freecodecamp.com/bash-shortcuts-to-enhance-your-git-workflow-5107d64ea0ff#.6r30rrj9l
Good Git!