A list of useful Git commands

Posted on 2018-06-29

Here's a list of Git commands that solve specific problems I encounter sometimes. I find these commands very useful, although I may not use them every day, which means I will tend to forget them and have to re-find them again and again. I'm storing them here for easy access. Maybe somebody's going to find them useful too.

Remove all changes from staging (but keep the actual changes)

python git reset HEAD -- .

Delete last commit but keep the changes

python git reset HEAD^

Delete all unstaged changes

python git clean -df git checkout -- .

Revert an accidentally executed git commit --amend

python git reset --soft HEAD@{1}

Reset the local branch to be exactly like the remote branch

python git fetch origin git reset --hard origin/branch_name

Start the modification of the last three commits (for example to rename them)

python git rebase -i HEAD~3

tags: git


Note: Comments are not shared with any 3rd party service. Email (which is optional) will not be published.