Wednesday, April 8, 2015

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(-)

No comments:

Post a Comment