Custom Search

Tuesday, January 28, 2014

Git How to keep all our commits on top of upstream commits

1)
Goto new devstack env
#cd /opt/stack/horizon

2)
Check default/existing remote repo and location
#git remote -v
origin    git://git.openstack.org/openstack/horizon.git (fetch)
origin    git://git.openstack.org/openstack/horizon.git (push)

3)
Add new remote repo.
Location of our remote repo where we are saving our horizon changes.
#git remote add mycld https://github.com/myCloud/horizon.git
#git remote -v
mycld    https://github.com/myCloud/horizon.git (fetch)
mycld    https://github.com/myCloud/horizon.git (push)
origin    git://git.openstack.org/openstack/horizon.git (fetch)
origin    git://git.openstack.org/openstack/horizon.git (push)

4)
Grab all branches and tags from the remote 'mycld'.
git fetch doesn’t touch your working tree at all, so gives you a little breathing space to decide what you want to do next.
git pull pulls from a remote branch and merges it.
git fetch only fetches from the remote branch but it does not merge
git pull = git fetch + git merge
#git fetch mycld
#git branch
*master

5)
Checkout the branch my_homepage from the remote 'mycld'.
#git checkout --track mycld/my_homepage
#git branch
* my_homepage
  master

6)
Note, right now I am in the branch 'mycld/my_homepage'.
#git pull

7)
Note, right now I am in the branch 'mycld/my_homepage'.
So the following command will takes commits which are only in the branch 'mycld/my_homepage'
and not in 'origin/master' and store it in temporary location.
Then appy all new commits (which are not in 'mycld/my_homepage') from 'origin/master' to 'mycld/my_homepage'.
Then try to restore all temporary stored commits one by one to 'mycld/my_homepage'.
So after this, In 'mycld/my_homepage' we can again see all our commits on top plus new commits from 'origin/master'.
#git rebase master

8)
Run 'git diff' to see the conflict
#git diff

9)
#Fix all conflicts manually (resolve all conflicts)

10)
Prepare the resoved files for commit
#git add name_of_modified_file(s)

11)
This command will automatically commit all resolved files and move to the next commit.
So we don't need to commit the resoved files manually.
#git rebase --continue

12)
#Repeat the steps from 8 to 11 until all the conflicts get fixed

13)
Optional
#git pull mycld my_homepage

14)
Optional
#Fix conflict manually and #git commit -a

15)
Push the rebased code to remote repo where we are saving our horizon changes.
#git push mycld my_homepage

No comments:

Post a Comment