Skip to content

Instantly share code, notes, and snippets.

@vurdalakov
Last active October 9, 2025 04:35
Show Gist options
  • Save vurdalakov/969a2e0197f541e2a67520eb6c34a29e to your computer and use it in GitHub Desktop.
Save vurdalakov/969a2e0197f541e2a67520eb6c34a29e to your computer and use it in GitHub Desktop.
Git cheatsheet

Remove last commit from local Git repository

git reset HEAD^

Remove last commit from remote Git repository

# remove commit locally
git reset HEAD^
# force-push the new HEAD commit
git push origin +HEAD

Remove last commit from remote Git repository but keep it locally

git push origin +HEAD^:<name of your branch, most likely 'master'>

Change last commit message in local branch

git commit --amend -m "New commit message"

Rename local branch

Rename current branch:

git branch -m <newname>

Rename any branch:

git branch -m <oldname> <newname>

Rename remote branch

In addition to renaming local branch:

rem Push local branch and reset remote branch:
git push origin -u <newname>

rem Delete old remote branch:
git push origin --delete <oldname>

Clone recursively without history

git clone --recursive --depth 1 -b master <repository url>

Show commit history

git log --pretty=format:"%h %ad [%an] %s" --date=short

Show last commit

git log -1

List stashes in all submodules

git submodule foreach "git stash list"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment