- Delete mutiple branch
git branch -D `git branch --list '3.2.*'`
- Apply the changes introduced by some existing commits
# one
git cherry-pick 88ce01c
# mutiples
git cherry-pick 88ce01c..42ab7f4
- Rename branch
git branch -m old-name new-name
- Delete all untracked files
git clean -df
- Keep in local branches sync with remote branches
git fetch --prune origin
- Recursively add files by pattern.
find . -name "filename" | xargs git add
eg: Find ./src
directory all index.js
files.
find ./src -name "index.js" | xargs git add
- See detail changelog of a file.
git blame file
# Process only line range 2 to 7
glit blame -L 2,7 file
- Use origin files overwrite local change.
git rest --hard origin/branch
- Create empty branch.
git checkout --orphan empty-branch
git rm -rf .
git clean -df
git commit --allow-empty -m "root commit"
- Clean all commits and duplicate current branch
git checkout --orphan latest_branch
git add -A
git commit -am "commit message"
git branch -D branch-name
git branch -m branch-name
- Specify an SSH key for git push
git config --add --local core.sshCommand 'ssh -i <<<PATH_TO_SSH_KEY>>>'
- Create a branch from another branch
# You can replace master to any branch you want to checkout from.
git checkout -b newBranchName master
- Update upstream
git branch --set-upstream-to <remotename>/<branchname>