1 minute

Easy forking with git

Did you ever wanted to fork a project but weren't exactly sure about handling updates from the master repository?

Published Jan 26, 2012 in programming with tags: bash git

With git and its aliases you can easily fetch updates from both your fork and master repository, merging them with one git alias:

git config alias.forkup '!git fetch origin -v; git fetch upstream -v; git merge upstream/master'

If you’re a git pro and feel you’re done now that’s great! But if you’d like to know how the whole fork setup works read on.

Here’s the detailed explanation on how to setup the fork repository and link it with its master:

Let’s initialize a new repository for your fork:

mkdir myfork
cd myfork
git init

OR if you start with a bare remote repository, just clone it to your machine:

git clone git@yourreposerver.com:myfork.git myfork

Next add the remote master repository you want to fork from to the local git configuration:

git remote add upstream git@masterserver.com:masterproject.git

(You can, of course, change the remotes name from upstream to anything you like… The current remotes can be listed with git remote -v)

Now you’re now ready to fetch changes from the upstream repository:

git fetch upstream

Pushing still works as ever, just push your changes to your remote with git push origin master.

With the little git alias at the top you’re able to easily fetch and merge the master repository and thus stay always up to date. The alias uses the verbose mode so you see what’s happening….

git config alias.forkup '!git fetch origin -v; git fetch upstream -v; git merge upstream/master'

Add --global if the alias is suppost to be available in all your git projects.

That’s all there is to it, easy and fast: the git way!

If you prefer bash aliases over the ones provided by git this should satisfy you:

alias gfu='git fetch origin -v; git fetch upstream -v; git merge upstream/master'
less than 1 minute

Watch folders with Hazel!

The latest tool I enjoy using is the rather unknown but brings ingenious and simple folder watching/actions to osx with a lot of configuration options.

Published Jan 16, 2012 in tools