Useful git commands

This is a list of useful git commands that I use often, or I always keep in mind.


git reset --soft It allows us to go back a commit. Keep the files on stage.

git reset --mixed It allows us to go back a commit. Remove the files on stage and keep them in working directory.

git reset --hard Remove the commits and delete the files.


git branch Show the existing branchs.

git branch -d branchName delete a branch.

git branch -m originalBranchName newBranchName Change the name of the branch.

git branch nameBranch create a branch.

git checkout -b nameBranch create a branch from the current.

git reflog show a list of the last commits, even if that commit was from a branch was deleted.

Stash (temporary storage)

git stash provisionally save changes so that we can, for example, change branches without committing.

git stash list show the files that are on stash

git stash apply Remove from temporary storage and return it for us to use. However, the elements are still in stash. If we want to remove them from there: git stash drop. WARNING: If we do the drop without having restored the files before, we lose them.


If we want to merge a specific commit from one branch to another, we place ourselves in the branch from which we want to get the commit and make a git log. Once the HASH of the commit has been identified, we copy it and move to the branch where we want to merge.

We make a git cherry-pick hashFromCommit and voila, we confirm with a git log.