1. cherry-pick 强制替换

    You can tell it to always prefer the changes of the commit you are cherry-picking:

    git cherry-pick commitish --strategy-option theirs
    

    commitish can be a SHA-1 hash of a commit, or a branch-name for the lastest commit of that branch, branch-name~1 for the commit before that etc.

    If you want to do the reverse, use:

    git cherry-pick commitish --strategy-option ours
    

    The shorthand for --strategy-option is -X (uppercase X).

  2. 设置全局 ignore 配置

    $ git config --global core.excludesfile ~/.gitignore_global
    
  3. 合并多个最近提交

    $ git rebase -i origin/master
    

    如果原始提交为:

    pick 16b5fcc Code in, tests not passing
    pick c964dea Getting closer
    pick 06cf8ee Something changed
    pick 396b4a3 Tests pass
    pick 9be7fdb Better comments
    pick 7dba9cb All done
    

    提交顺序从上到下分别为从旧到新,所以需要将新的提交合并到旧的提交上,因此 pick 的应该是最旧的那个 commit,squash 的是被合并的新的 commit:

    pick 16b5fcc Code in, tests not passing
    squash c964dea Getting closer
    squash 06cf8ee Something changed
    squash 396b4a3 Tests pass
    squash 9be7fdb Better comments
    squash 7dba9cb All done
    
  4. 忽略 pyc 文件

    > cat .gitignore
    *.pyc
    

    然后通过下面这个命令清除已有的 pyc 文件:

    $ find . -name "*.pyc" -exec git rm -f "{}" \;
    
  5. pull 拉取所有的分支

    [root@liqiang.io] # git fetch --all
    [root@liqiang.io] # git pull --all
    [root@liqiang.io] # git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
    
  6. push 推送所有的分支和 tag 到远程

    [root@liqiang.io] # git push REMOTE --mirror