A triangle workflow involves an upstream project and a personal fork containing a development branch of the project.
This configuration makes git pull
merge changes from the upstream but git push
send local commits to the personal fork.
However those config settings only work on relatively recent versions of git; 1.7.9 doesn't support the required remote.pushdefault
config setting so you will have to explicitly tell git push
which remote to push to.
This gist does not attempt to explain exactly what these commands do, it's intended as a cheat-sheet/reminder.
- Fork the project on
https://github.com/<project>
- Rename 'origin' to 'upstream' and add a new remote 'github':
$ cd <project>
$ git remote rename origin upstream
$ git remote add github [email protected]:<user>/<project>.git
- Clone the newly forked branch:
$ git clone -o github [email protected]:<user>/<project>.git
- Add a remote 'upstream' to point to the official repository:
$ cd project
$ git remote add upstream [email protected]:<organization>/<project>.git
$ git fetch upstream
- Set the default push remote to be the new fork:
$ git config remote.pushdefault github
$ git config push.default current
The above commands are optional and won't work on older versions of git such as 1.7.9, they save having to type the names of the remote and branch when pushing changes to github.
- Create and checkout a local branch where the work will be done, based off the upstream/master branch:
$ cd <project>
$ git checkout -b <development> upstream/master
- Develop on this branch, committing freely to the local repository.
$ git add <files>
$ git commit -m '<message>'
- Push commits to the remote
github/<development>
branch using:
$ git push
These commands are quite simple because of the options used in the earlier steps.
On older git versions you have to use git push github
instead.
There are two ways to import changes committed to the master branch before this branch gets merged. If there are no conflicts between the two sets of changes though it may not be necessary to do either.
- To merge changes from the
upstream/master
branch:
$ git pull
- To rebase this branch onto the latest
upstream/master
commit:
$ git pull --rebase
It is relatively easy to commit changes to the upstream/master branch while you're still developing in your private development branch. To switch your working directory to the master, use
$ git stash save <message> # Optional, saves uncommitted changes
$ git checkout master
$ git pull
Now you can make any changes needed. To commit and push them to the upstream repository
$ git add <files>
$ git commit -m '<message>'
$ git push upstream
To get back to where you were on your development branch again
$ git checkout <development>
$ git stash pop # Optional, restores saved uncommitted changes
-
When you're ready for review, issue a pull request for this branch through github.
-
After the branch has been merged, delete it using
$ git checkout master
$ git pull
$ git branch -d <development>
@geoffrey-eisenbarth The text of that hint comes from the server, and it doesn't know what name you used locally for your remote pointing to the project, so it uses 'origin' which is the default name for a remote if you don't specify one (it mentions that in the first line of the hint). If you've been following my gist instructions then that remote is named 'upstream' in your local clone, so yes you would need to translate the suggestion to
git checkout --track upstream/dev
in that case.