Sunday, March 18, 2018

Forking and maintaining a git repository

There are many public repositories which at times we want to fork and continue our path. However, at the same time, we want to keep pulling the changes from the original repository also. In this post, we will look into how to fork a repository and how to pull the changes in future.

Forking

Let's say we want to fork a repository 

https://github.com/lalitmcb/rms

This is an actual repository so you use it to try it out.

First clone the repository locally

git clone https://github.com/lalitmcb/rms.git

Now let's say you want to make a new repo with your username at some location. For example purpose, we will assume github and we want to create the repo with name "copy".

Go to rms folder

cd rms
git push --mirror https://github.com/<your username>/copy.git
Delete the rms folder and you can clone the new copy repository for further work

Merging from the original repo


Usually, you want to do it in the master branch. Synching the master of original repo with the fork.

Check out the master

git checkout master

Pull the changes from original repo to the local master branch

git pull https://github.com/lalitmcb/rms.git master

Push the changes to your repo. There might be conflicts which need to be resolved.

git push origin master

Once the changes are in master in your repo. you can pull those changes in the other working branches.

No comments:

Post a Comment