Mirror local repo to reflect remote
git fetch origin
git reset --hard origin/master
Delete remote branch
git push origin --delete <branchName>
Add submodule to specific branch
git submodule add -b branch-name [email protected]:user/repo.git directory
Force merge from remote (overwrite tree)
git fetch origin master
git reset --hard FETCH_HEAD
git clean -df
Quick Conflict resolution
git checkout [--theirs|--ours] <file|.>
git mergetool --tool=emerge [file] # keys: (n) next, (a|b) choose side, (q) quit
Cherry-picking (merge single commit only)
git checkout new-feature
git log (get <commit-id> of the desired change)
git checkout branch-to-insert-changes
git cherry-pick <commit-id>
Track a remote repository fro branch
git remote add <remote> [email protected]:user/repo.git
git branch --set-upstream <branch-name> <remote>/<branch-name>
# Check .git/config
[remote "remote"]
url = [email protected]:user/repo.git
fetch = +refs/heads/*:refs/remotes/remote-name/*
[branch "branch-name"]
remote = remote-name
merge = refs/heads/master
Track ignored file just once
git update-index --assume-unchanged [FILENAME]
Then if you want to track the file later
git update-index --no-assume-unchanged [FILENAME]
Get repository size
git count-objects -vH
Compress repository (https://stackoverflow.com/a/2116892/165750)
git reflog expire --all --expire=now && git gc --prune=now --aggressive
Clone only latest commit
git clone --depth 1 <repository-url>