How to keep your forked repositories in sync with the source repository

Pocket

This blog post aims to answer the following questions.

  • How to contribute to Open Source Projects (Partially)?
  • How to keep forked repositories in sync with the source repository ?
  • How to pull the commits from source repository to the forked repository?

I often forked open source repositories found in github and also commit back to the repositories whenever I feel to. However, this may seem obvious who has been doing these kind of thing. But for someone who is completely new this is kind of mess and it’s hard to figure out the right way to do it at first. So, I do not claim that the way I show here is right. I am just showing how I do it my way and would like to share it with others.

I have forked repository from github repo. I already have it cloned in my local repository. I had forked it long ago. So, when I get back to the forked repo, I get a message saying that My repository is 3 commits behind.

Introduction

Now, before I can contribute to the main repo I have to first sync up my repo with the forked one. To do that I have to bring in all the commits that are missing from my repo, those commits are as follows:

  • Add PHP School to intro FAQ
  • Add Snappy library
  • Add packages to work with screenshot APIs

I get inside my forked repository i.e. https://github.com/samundra/php-faq

php-faq

is the folder that I have my forked repo on my local machine. So I use

$ cd php-faq

to get inside the folder. Inside the folder as you can see below “git remote -v” displays the “origin” as the remote.

To be able to pull in changes, I will add another remote which is my forked repository. I use

git remote add wwphp https://github.com/wwphp-fb/php-resources

Now when I do

$ git remote -v

it will display origin and wwphp under remote list.

Git Remote Add

Now, I fetch all the meta information from the newly added repo i.e. wwphp. I am only interested in the master branch and thus fetching information from that particular branch only.

git fetch wwphp master

Now, to see the commits that my repository is missing I use

$ git log --oneline origin/master..wwphp/master --left-right

Fetch metainformation from remote repository

It basically lists out all the commits that are in wwphp/master branch but no in origin/master (my forked repository).

We can see that we don’t have above 3 commits on my forked repository.
Commits on current repo

Just to confirm:
Commits on current repo

Now, to pull in the commits that my repo is missing I will use

$ git merge wwphp/master

Merge github commits from remote repo to forked repo

To confirm that we have successfully pulled in the commits we can see the “git log” output. The above output message “Your branch is ahead of ‘origin/master’ by 3 commits.” are shown because I haven’t pushed them to my forked repo on github. Once I push the currently made changes to my github repo then this message will stop showing up.

View merged commits

Finally push all the newly introduced commits to my forked repository.
Final push to the github

Now, the message has changed from “3 commits behind” to “branch is even” which means that we have successfully pulled in all the commits from remote repo to our forked repositories.

Note:

Instead of “git fetch wwphp master” we can also use “git fetch https://github.com/wwphp-fb/php-resources/ master” similarly we can use “git pull https://github.com/wwphp-fb/php-resources/ master”. However, I would suggest you use the fetch and then see the commits that will come in and whether you would like to merge or not.

Let me know if you have any confusions on this. I will try to answer them.

Happy forking ūüôā

Nepal gets a new constitution 2072

Pocket

CONSTITUTION of NEPAL 2072

Today, Nepal got its most awaited constitution 2072. Being Nepali this is proud moment for me and for all Nepalese. There has been clashes between political leaders, parties. Despite all the shortcomings they gave us the constitution 2072. I¬†hadn’t expected the constitution would come so sooner.¬†

Here is my facebook status.

Congrats to all of us ‚Ä™#‚ÄéNepalese‚Ĩ for the new constitution 2072. Celeberation begins smile emoticon with Asee Shrestha being an Engineer eight years is not a long span for something that has to do with country’s revolution. Once again thanks to all the political parties, leaders who showed their active participation in this historical moment.

[How To] Add Genymotion to Ubuntu Dash Menu

Pocket

Genymotion Dash
At First create a “genymotion.desktop” file in “usr/share/applications/” folder. Then copy and paste the below contents into “genymotion.desktop” file.

[Desktop Entry]
Encoding=UTF-8
Name=Genymotion Simulator
Comment=Android Simulator fast and reliable
GenericName=Genymotion Simulator
Exec=/usr/local/bin/genymotion
Terminal=false
Type=Application
Icon=/media/BACKUP/genymotion/icons/icon.png
Categories=Application;Network;Internet;
StartupWMClass=Genymotion
StartupNotify=true

In above file, I have created symbolic link to my genymotion in “/usr/local/bin/genymotion”. I have installed genymotion in “/media/BACKUP/genymotion/” thus my command to create symbolic link to genymotion is:

$ sudo ln -n "/media/BACKUP/genymotion/genymotion /usr/local/bin/genymotion"

Now, change the “Icon” to point to the icon.png file which is inside the genymotion folder.

If you have any confusions following this walkthrough. Please let me know in comments.

Thanks,

Vagrant syntax for adding existing local box

Pocket

Syntax provided below can be used on windows to add existing local vagrant boxes.

vagrant box add custom32 file:///f://Vagrant//precise32.box

In the above command custom32 is the name for the vagrant box and “file:///f://Vagrant//precise32.box” is the locally available box. This box was downloaded from internet and placed locally on f drives Vagrant folder.

Also see the screenshot below:

vagrant box add, syntax to add local vagrant boxes
Syntax to add vagrant boxes