Showing posts with label sync. Show all posts
Showing posts with label sync. Show all posts

Wednesday, April 8, 2015

Working with forked git repo- proper way to sync- part2

After writing my previous blog post, I played around with github UI a bit and found another method to sync forked repository with the original. So decided to write down those steps here.

1. Browse your forked repository. I'm using https://github.com/udarakr/carbon-store/ repository which I have forked from https://github.com/wso2/carbon-store. You can notice the organization difference by looking at the URL.


You can notice that my carbon-store fork is 71 commits behind the original.

Then press the Pull Request link and you will get something similar to the following.



Since my fork is 1 commit ahead, by default github suggests me to create pull request  using this commit. But my intension is different here.

So click head fork drop down and select a different one. Other than the one selected at the moment. So I choose splinter/carbon-store and this is my outcome. (Don't worry about this step,  you can select whatever you want. This is a trick to change base fork to head fork and vice versa)

  
Now click on the base fork and select your forked repository/branch and then change head fork to the original. You will get something similar to the following.


Now press the Create pull request button and open a pull request.




Since I have 71 commits involved in this pull request I have to scroll a bit to find the Merge pull request button.



Press Confirm merge and you are done !!



Now if I browse my forked repository, I can see that I'm no more behind the original repo :)



Working with forked git repo- proper way to sync

Thought of writing this simple post after seeing one of my colleagues way of updating forked git repo. This guy used to delete the forked repo and fork again to get latest updates (:D Yes I'm talking about you).

The proper way of syncing is pretty simple (may be not simple as delete/fork method). Let me explain this in two steps.

1. Configure remote repo for our fork

git remote -v command will list the existing remote repositories.
udara@udara-home:~/wso2/git/fork/carbon-apimgt$ git remote -v
origin    git@github.com:udarakr/carbon-apimgt.git (fetch)
origin    git@github.com:udarakr/carbon-apimgt.git (push)
You can add a new remote repository by providing git remote add upstream command.
udara@udara-home:~/wso2/git/fork/carbon-apimgt$ git remote add upstream git@github.com:wso2/carbon-apimgt.git 
Now if I run the git remote -v command again,
udara@udara-home:~/wso2/git/fork/carbon-apimgt$ git remote -v
origin    git@github.com:udarakr/carbon-apimgt.git (fetch)
origin    git@github.com:udarakr/carbon-apimgt.git (push)
upstream    git@github.com:wso2/carbon-apimgt.git (fetch)
upstream    git@github.com:wso2/carbon-apimgt.git (push)
2. In order to sync your fork run git fetch upstream command.upstream is the name you provided earlier while configuring the remote.
udara@udara-home:~/wso2/git/fork/carbon-apimgt$ git fetch upstream
remote: Counting objects: 355, done.
remote: Compressing objects: 100% (173/173), done.
remote: Total 355 (delta 48), reused 5 (delta 5), pack-reused 80
Receiving objects: 100% (355/355), 256.29 KiB | 56.00 KiB/s, done.
Resolving deltas: 100% (53/53), done.
From github.com:wso2/carbon-apimgt
 * [new branch]      master     -> upstream/master
 * [new branch]      release-1.3.0 -> upstream/release-1.3.0
 * [new branch]      release-1.3.1 -> upstream/release-1.3.1
 * [new branch]      release-1.3.2 -> upstream/release-1.3.2
 * [new branch]      release-1.3.3 -> upstream/release-1.3.3
 * [new branch]      release-1.9.0 -> upstream/release-1.9.0
 * [new branch]      release-2.0.0 -> upstream/release-2.0.0
Make sure you switch to the correct branch (in my exercise it's release-2.0.0) . You can verify that by running git branch -a command.

Now run git merge upstream/release-2.0.0. this makes my local release-2.0.0 branch sync with the upstream repository.
udara@udara-home:~/wso2/git/fork/carbon-apimgt$ git merge upstream/release-2.0.0
Updating a68742d..4000cbd
Fast-forward
 .../org/wso2/carbon/apimgt/api/APIProvider.java    |  29 ++
 .../wso2/carbon/apimgt/impl/APIProviderImpl.java   | 466 ++++++++++++++++++++-
 .../src/main/resources/config/rxts/api.rxt         | 107 ++---
 .../resources/apipublisher/scripts/apipublisher.js |  29 +-
 4 files changed, 548 insertions(+), 83 deletions(-)