Git cheatsheet

ยท

2 min read

Few commands I found very useful during development.

CommandDescription
git commit -am "message"add and commit all trakced files
git fetch --all --prunefetch all remotes, delete remote branches which are dead
git reset --mergeabort merge, reset as before (also if there are local commit not pushed yet)
git merge --strategy-option theirs [branch]merge branch into current branch, keeping their work in conflicts
git branch --unset-upstreamremove upstream branch
git reset myfile.jsremove from staging area
git commit --amend --no-editamend without edit message
git checkout -switch to previous branch
git checkout [branch] -- path/to/file.scssget file from another branch and copy to current branch
git stash -ustash all files (also untracked ones)
git reset --soft Aremove files, but still available in staging area
git reset --mixed Agit reset A (default) remove files also in staging area
git reset --hardremove files as they never existed
git stash cleardelete all stashes
git fetch origin; git reset --hard origin/mainrestore as remote main branch
git log --tags --simplify-by-decoration --pretty="format:%ci %d"show tags details
git log --graph --abbrev-commit --decorateshow commits with decorative branches
git push origin :feature/branchnamedelete remote branch
git push origin --delete feature/branchnamedelete remote branch
git push origin --allpush all local branches
git fetch --prune --prune-tagsremove local tags, align tags to remotes
git ls-remote --tags originlist all remote tags

Rename a git tag

git tag [new] [old]
git tag -d [old]
git push origin :refs/tags/[old]
git push --tags

When you fetch remote tags, be sure you have the updated tags

git pull --prune --tags

GitLab branch compare

  • Open the left sidebar
  • Click on Repository > Compare
https://github.com/giuliachiola/super-blog-11ty/compare/[source]...[target]

Example:

https://github.com/giuliachiola/super-blog-11ty/compare/main...develop