星期日, 六月 16

git 小技巧:Github forking after cloning

git 我一直在本地随用随 commit 很方便,跟远程push pull 用得较少,基本是常规用法,今天碰到一个情况,github 上 fork 了别人的项目,做了修改后要改项目的名字,麻烦的是我还是在原来 clone 他的本地文件上做修改的,摘抄 google 到的方法如下:

http://blog.csanchez.org/2011/01/06/github-forking-after-cloning/


Github forking after cloning
When you want to change/contribute to other people’s projects that you don’t have access to you usually fork the project, and then use your read+write fork.
What if you first cloned their repo and made local commits that you now want to contribute? You don’t want to mess with patches, so here’s what I did to contribute a small fix to the example project from Apache Maven 2 Effective Implementation, a great book by Brett Porter and Maria Odea Ching.
  1. Fork the project repo at Github (athttps://github.com/brettporter/centrepoint/)
  2. In my local clone, I renamed the remote origin to upstream
  3. Add a new remote called origin pointing to the read+write fork
  4. Change the master branch remote to origin instead of upstream
  5. Fetch the remote and push your changes
git remote rename origin upstream
git remote add origin git@github.com:carlossg/centrepoint.git
git fetch origin
git branch --set-upstream master origin/master
git push origin