Git Fork: A Short Note

ยท 161 words ยท 1 minute read

A fork is a new repository that shares codes and visibility settings with an “upstream” repository. Forks are used to iterate on ideas, or maintain changes to a repository when a user does not have write access to upstream, or simply prefers to keep a personal copy.

How to fork a repository ๐Ÿ”—

A repository can be forked from the GitHub.com page of the repository.

How to fork a repository

How to update the forked repository ๐Ÿ”—

Add the remote, call it “upstream”.

git remote add upstream https://github.com/whoever/whatever.git

Fetch all the branches of that remote into remote-tracking branches.

git fetch upstream

Assuming that local changes are in the master branch, moving to this branch.

git checkout master

Rewrite the master branch so that any commits that aren’t already in upstream/master are replayed on top of the other branch.

git rebase upstream/master

Lastly, force push to the forked remote repository.

git push -f origin master

Further reading ๐Ÿ”—

  1. GitHub documentation about forks
  2. An excellent discussion on stackoverflow about forks