git processes - kornysietsma/technical-notes GitHub Wiki

Working with a PR

check out a branch

git checkout -b tt666-my-funky-branch

make changes, commit, push to the branch

git push -u origin tt666-my-funky-branch

(or --set-upstream)

then go to the gui to make a pr, or use hub

hub pull-request

Updating when master changes

git fetch
git rebase origin/master

See https://stackoverflow.com/questions/7200614/how-to-merge-remote-master-to-local-branch for a good summary of the options

Working with forks, where origin is the source of the fork

clone the origin

git clone [email protected]:kornysietsma/foo.git
cd foo

add a named remote to point to the fork (already forked on the web)

git remote add my-fork [email protected]:kornysietsma/foo.git
git fetch my-fork

create a local branch, push to the fork

git checkout -b branch-name
git push my-fork branch-name:branch-name

or if there's already a branch on the fork

git checkout branch-name
git push my-fork

or you can set the origin permanently

git push --set-upstream my-fork branch-name

updating the fork from origin

git checkout master
git pull origin master
git push my-fork

this won't update the branch though - that's another exercise.

Pruning old branches

git fetch -p fetches and prunes any remote-tracking branches that no longer exist on the remote

git branch -r --merged origin/master removes branches that have been merged

the following is a bit more aggressive to do a similar thing - I can't really remember the difference

git branch --merged | egrep -v "(^\*|master)" | xargs git branch -d

Moving changes between repos

Save patch files to a 'patch' directory, for every commit since revision:

git format-patch -o patch revision

Apply patch file from the ones saved above, with 3-way merge if possible:

git am -3 path-to-old-patch/0001-patch-file-name.patch

and then commit.

see also https://www.kernel.org/pub/software/scm/git/docs/git-format-patch.html and https://www.kernel.org/pub/software/scm/git/docs/git-am.html