Show Menu

Git useful commands and stuff

This is a draft cheat sheet. It is a work in progress and is not finished yet.


git fetch origin --prune
git checkout --track origin­/br­anc­hname


git fetch
git checkout feature/feature-x
git commit -m "[Feature] feature x implemented"
git push
git checkout develop
git pull
git checkout feature/feature-x
git rebase develop
git add fixed files list
git rebase --continue
git checkout develop
git merge --no-ff feature/feature-x
git push
git branch -D feature/feature-x
git push origin :feature/feature-x


git diff --staged

# what has changed in this file from last commit 
git diff HEAD~1..HEAD file.txt

# compares file from current branch to master
git diff HEAD..master file.txt

# compares the stash against the commit it is based on
git diff stash@{0}^!

# see the most recent stash
git stash show -p
git stash show -p stash@{0}

Useful Commands

# which commit does this branch come from?
git merge-base new_branch old_branch

# merged branches not deleted
for branch in `git branch -r --merged origin/master | grep -v HEAD`;do echo -e `git show --format="%ai %ar by %an" $branch | head -n 1` \\t$branch; done | sort -r

# Amend a (non-pushed) commit
git commit --amend --no-edit

# clear local tags
git fetch --prune origin "+refs/tags/:refs/tags/"

git remote show origin

git checkout --track origin/branchname

# reset local branch to remote's HEAD
git reset --hard origin

git worktree


git log --oneline
git log --stat
git log --name-status
git log --follow --pretty=format:'%an (%ae)' file.c | sort | uniq


        excludesfile = ~/.gitignore
  path = ~/.gitconfig-local
        prune = true
        rebase = merges
        default = upstream
[color "branch"]
        current = yellow reverse
        local = yellow
        remote = green
[color "diff"]
        meta = yellow bold
        frag = magenta bold
        old = red bold
        new = green bold
[color "status"]
        added = yellow
        changed = green
        untracked = cyan
        remoteBranch = cyan
        hist = log --color --graph --oneline --decorate --all
        lg = log --color --graph --oneline --pretty=format:'%C(yellow)%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
        st = status -sb
        co = checkout
        br = branch
        pushf = push --force-with-lease
        ver = describe --tags
        fuckup = commit --fixup HEAD
        praise = blame