Skip to content

Instantly share code, notes, and snippets.

@simbathesailor
Forked from ospatil/git.txt
Created November 29, 2019 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simbathesailor/06e2b78d043016d148f41f5d2d320739 to your computer and use it in GitHub Desktop.
Save simbathesailor/06e2b78d043016d148f41f5d2d320739 to your computer and use it in GitHub Desktop.
Important git command for branch and tag management
1. get list of remote tags
git ls-remote --tags origin
2. get list of local tags
git tag
3. remove local tag
git tag -d <tag name>
4. delete remote tag
git push origin :<tag name>
5. show all branches
git branch -a
6. show only remote branches
git branch -r
7. delete local branch
git branch -d the_local_branch
8. delete remote branch
git push origin --delete <branchName>
9. resetting a branch to specific commit
git reset --hard <commit-hash>
10. to revert n commits
git reset --hard HEAD~n-1
git push -f origin <branch-name>
11. Cleaning untracked files from a branch -
(Just show what will be deleted) git clean -fn
(Actually delete) git clean -f
(to remove directories also) git clean -fd
12. Tagging a particular older commit in git -
git tag -a v1.2 9fceb02 -m "Message here"
13. Easiest release process on github -
npm version [version or version token such as minor, patch etc.]
git push origin --tags
git push origin master
npm publish
14. Squash several commits into one -
http://makandracards.com/makandra/527-squash-several-git-commits-into-a-single-commit
15. Create a branch with the tag
git branch {tagname}-branch {tagname}
git checkout {tagname}-branch
16. Include the fix manually if it's just a change ....
git add .
git commit -m "message"
17. Delete and recreate the tag locally
git tag -d {tagname}
git tag {tagname}
18. Delete and recreate the tag remotely
git push origin :{tagname} // deletes original remote tag
git push origin {tagname} // creates new remote tag
(15, 16, 17 and 18 thanks to https://gist.github.com/danielestevez/2044589)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment