Daniel Siepmann - Coding is Art

Blog Post

Ease working with Git Forks

Published: , Updated:

Topics: git

Introduction

My usual workflow for working on forks looks like this: Clone the original repo, add my own fork as second remote. Fetch all changes from original repo, create a new branch, and push this branch to my own fork. The pushing is where the default sucks. Git will by default push to origin which is the original repo without push rights.

I'll explain two solutions I've used so far to ease this little issue with Git.

Solution 1: Change default push

Right now I'm using this solution. It changes the default remote for pushes. That way new branches will be pushed to a different remote than “origin”. This can be done via: git config remote.pushDefault own. This will alter the .git/config file and tell git to push to remote “own” by default, instead of “origin”.

The full workflow:

  1. Clone the original repository
  2. Add own fork as remote “own”
  3. Configure git to push to “own” by default

Now each time one is working on the fork:

  1. git fetch
  2. git switch -c <new branch>
  3. git commit -a
  4. git push

Solution 2: Change default remote to own fork

That's the solution I've used in the past. It works by sticking to git defaults and using the own fork as default remote.

The workflow looks like this:

  1. Create a fork
  2. Clone the fork
  3. Add original repository as another remote (I've used “official”)

Now each time one is working on the fork:

  1. git fetch official
  2. git switch -c <new branch>
  3. git commit -a
  4. git push

Why do I use solution 1?

There is not much difference in both solution. The only difference is that solution 2 still needs an explicit statement of a remote while fetching.

That's why I prefer solution 1. I consider my fork as a workaround due to how most providers handle the workflow. My mind still is in the mood of a single repository with a single remote. I don't want to worry about multiple remotes. Solution 1 more or less hides the second remote from my workflow and I can work as usual.

Further reading