Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull master into remote branch on origin

Tags:

git

github

I have a two remote branches: origin/master and origin/my_remote_feature

I have checked out my_remote_feature using git checkout --track -b origin/my_remote_feature

There are a couple of changes made in master that I want to pull into my branch that tracks the remote branch. How do I go about it ?

like image 947
goutham_kgh Avatar asked Jan 19 '16 16:01

goutham_kgh


People also ask

How do I pull code from master to remote branch?

So what you're saying is you want to bring the changes from your master branch, into your dev branch? Switch to dev branch with a git checkout dev . Then git pull --rebase origin master . If you are lucky, there will be no conflicts and dev will have the latest changes from master.

How do I push my master branch to my new origin remote?

Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch. Simply use a git push origin command on subsequent pushes of the new branch to the remote repo.

How do I pull remote master?

In case you are using the Tower Git client, pulling from a remote is very easy: simply drag the remote branch and drop it onto your current HEAD in the sidebar - or click the "Pull" button in the toolbar.


3 Answers

git rebase origin/master

Is all you really need to do. then resolve any conflicts. You might need

git rebase --continue

if there are are conflicts. This will put my_remote_feature commits on top of the HEAD of origin/master. Re-writing history as it were.

git merge origin/master

Is also a possibility. However, you will find that all the commits to master will become part of your remote_feature commit history. Which you may not want. Generally rebase is better to keep your commit history pristine. :)

like image 172
Ryan Avatar answered Oct 20 '22 07:10

Ryan


One cool way to do this is to rebase origin/master into your remote branch. You can follow the following rebase workflow;

  1. Check out to your local my_remote_feature branch and pull changes from that branch. git pull origin my_remote_feature

  2. Do a git fetch

  3. Then rebase origin/master like git rebase origin/master

  4. If all works successfully, push your new updates. git push origin my_remote_feature

This will bring all the changes on master on top of your changes in my_remote_feature. If there are any conflicts, you will have to resolve them along the way and make sure you add files after resolving conflicts then do a git rebase --continue after every conflict resolutions.

You can refer to the git rabase doc for more information.

like image 27
Olalekan Sogunle Avatar answered Oct 20 '22 07:10

Olalekan Sogunle


Merge the master branch to your feature branch and then push the changes.

like image 41
René Höhle Avatar answered Oct 20 '22 07:10

René Höhle