Ubuntu

2. Configure recommended defaults

Tell git branch and git checkout to setup new branches so that git pull will appropriately merge from that remote branch. Without this, you will have to add --track to your branch command or manually merge remote tracking branches with fetch and then merge

If the patch needs updating, create a new patch and attach it to the relevant ticket

git diff master > ticket1234.diff

Repeat for every ticket you have worked on.

Testing everything in the integration branch

Goal: a place to try out the code from several tasks together. master can not be used for this as it is used for tracking upstream. This is a temporary branch that can be removed or reset to the same state as master after testing is done.

Create the branch

git checkout -b integration master

Merge in all task branches, fix any conflicts that occur in the task branches (i.e. they should merge cleanly)

Reset the branch back to master's state (to re-integrate all tickets again later):

git reset --hard master

Deleting a remote branch

Deleting a remote branch is somewhat unintuitive:

Delete the local branch

git checkout master
git branch -d ticket1234

Delete the corresponding remote one

git push origin :ticket1234

If something went wrong

If you haven't done anything out of the ordinary, but see

$ git push
...
! [rejected] master -> master (non-fast forward)
...

then most likely your branch (master in this case) is out of sync with the remote branch.

git pull

should alleviate the problem and git push should work again.

Generally, non-fast forward means that the local history differs from the remote history and pushing would change remote history.
Although rewriting history may wreak havoc if someone has forked your repository after the changed point, it is sometimes necessary.

On master

You can reset master to a one-to-one copy of upstream as follows:

git checkout master
git reset --hard upstream/master

If the reset changes history, you'll get the non-fast forward error when doing a git push. A forced push is required in this case:

git push --force

On a branch

Switch to the branch

git checkout ticket1234

You can manually remove or glue commits together with

git rebase -i master

To abort the rebase, just remove all non-commented lines.

If something went wrong during rebase and you want to undo the rebase:

Find out the state identifier before the rebase:

git reflog

Switch back to that state

git reset --hard HEAD@{NUMBER_FROM_REFLOG_HERE}

This works for all other similar problems as well, e.g. for backing out a merge.