Useful GIT commands for everyday use

Clone a repository

git clone gitcommands
cd gitcommands
git clone --single-branch --branch my-branch

Cleaning a repository

git reset --hard HEAD
git clean -f
git checkout filename
git reset [-- path/to/file]
git reset --soft HEAD~1
git update-ref -d HEAD

Pulling changes

git pull source-branch
git remote add upstream
git fetch upstream
git rebase upstream/my-branch

Merging changes

git merge --abort
git merge -Xtheirs [branch-name]
git merge -Xours [branch-name]


git remote add origin
git push -u origin master


git reset --hard e8fe18df3a8ff8220b9158f53a37dc163f45bc67
git push -force origin master

Working with branches

git branch
git checkout -b new-branch
git push -u origin new-branch
git checkout test-branch

Deleting Branches

git branch -d -r my-branch
git push origin --delete my-branch
git remote prune origin
git fetch -p
git checkout master
git branch -vv | grep ‘: gone]’ | awk ‘{print $1}’ | xargs git branch -d



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Francisco Igor

Francisco Igor

Programming from the past century. Worked with many programming languages and software development tools for desktop, web and mobile.