Custom Search

Monday, August 10, 2015

How to git cherry-pick commit from another/upstream repository

1)
Clone forked repo
#git clone https://github.com/JioCloud/contrail-third-party.git
#cd
contrail-third-party.git

2)
Check all existing branches
#git branch
  branch1
  branch2
* master

3)
Add upstream remote (upstream repo) and name it "upstream_remote"
#git remote add upstream_remote https://github.com/Juniper/contrail-third-party.git

4)
Check all remotes
#git remote -v
upstream_remote    https://github.com/Juniper/contrail-third-party (fetch)
upstream_remote    https://github.com/Juniper/contrail-third-party (push)
origin    https://github.com/JioCloud/contrail-third-party (fetch)
origin    https://github.com/JioCloud/contrail-third-party (push)

5)
Fetch the latest version of master (fetch all branches) from remote "upstream_remote"
#git fetch upstream_remote

6)
Goto the branch where you want to apply the commits.
$git checkout R1.10
* This "R1.10" branch is in "origin" remote

7)
cherry-pick the commit from newly added  upstream_remote and apply.
$git cherry-pick [commit-id]

* You can use $git log command to find the commit-id from upstream_remote branches.
* Example:
   $git log -n 5 upstream_remote/branch_name





No comments:

Post a Comment