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.
- Fork the project repo at Github (at https://github.com/brettporter/centrepoint/)
- The original read only url was https://github.com/brettporter/centrepoint.git
- My fork url is now git@github.com:carlossg/centrepoint.git
- In my local clone, I renamed the remote origin to upstream
- Add a new remote called origin pointing to the read+write fork
- Change the master branch remote to origin instead of upstream
- 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
I needed a
git fetch origin
before line 3 (git branch ...
)you are right, I have updated the post moving
git fetch origin
up to line 3“`git branch –set-upstream master origin/master“` is no longer supported. Instead use “`git branch –set-upstream-to origin/master master“`