Skip to content

Instantly share code, notes, and snippets.

@sreekanthsnair
Last active October 16, 2018 10:19
Show Gist options
  • Save sreekanthsnair/f7f51121e60d5d858941a58174322377 to your computer and use it in GitHub Desktop.
Save sreekanthsnair/f7f51121e60d5d858941a58174322377 to your computer and use it in GitHub Desktop.
Most useful git commands

Revert and push changes to a specific commit

git push -f origin <checksum>:<branch_name>

Resetting a branch to exactly match the remote branch

git fetch origin
git reset --hard origin/<branch_name>

Delete a tag from local & remote

git tag -d <your_tagname>
git push origin :refs/tags/<your_tagname>

Creating branch from tag

git checkout origin master
git fetch origin
git branch <new_branch> <your_tag>
git checkout <new_branch>
git push origin <new_branch>

Record conflict resolution for a future use

git config --global rerere.enabled true
git config --global rerere.autoupdate true

Globally setting automatically use rebase merge

git config --global pull.rebase true

Force existing branches to use rebase

git config branch.*branch-name*.rebase true 

Clean all deleted remote git branch from local

git fetch origin --prune

Reverting a reset commit

git reflog
git reset <hash>

Renaming a branch

git branch -m new-name
git push origin :old-name new-name
git push origin -u new-name

Few common cheatsheet references

https://www.git-tower.com/blog/git-cheat-sheet

https://services.github.com/on-demand/downloads/github-git-cheat-sheet.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment