9

I am working on a branch called create. I have to pull the changes that are made into my branch. I already have done -

git checkout master

git pull origin master

and now I have to merge it. What's the way to merge it?

Naman
  • 27,789
  • 26
  • 218
  • 353
mukhilsaravanan
  • 115
  • 1
  • 1
  • 9

3 Answers3

8

Considering that you have updated the master on your local using

git checkout master && git pull origin master

You can pull the changes to create branch also using -

git checkout create && git pull origin master

Edit - As suggested by @Zarwan, rebase is also another option. For details on when to use which, please look into When do you use git rebase instead of git merge?

Community
  • 1
  • 1
Naman
  • 27,789
  • 26
  • 218
  • 353
  • If you follow the above commands, you won't have to `merge` explicitly but resolve conflicts if there be any. `git commit` and `git push origin create` should work fine to push your code then. – Naman Nov 24 '16 at 04:14
  • will git merge master, pull all the changes into create branch? I am new to comman line – mukhilsaravanan Nov 24 '16 at 04:19
  • @mukhilsaravanan If it helped, do mark it as an answer for others to benefit from. – Naman Sep 16 '17 at 12:10
6

It is recommended to rebase your feature branch with master rather than merge it. Details below

rebase - if you are still working on your feature branch create, then rebase your feature branch to master. This allows you to work on your branch with the latest version of master as if you've just branched off your master.

git checkout create
git rebase master

merge - use it when you finish your task on your feature branch and want to merge it to other branches. For example, when you finish your work on create branch and want to merge it with master.

git checkout master
git merge create
git push origin master

This operation also generates a merge commit on your master branch.

sa77
  • 3,563
  • 3
  • 24
  • 37
  • Why is it recommended to rebase rather than merge? – Matthias Dec 23 '22 at 00:14
  • @Matthias rebasing will result a linear history of your commits, making it easier to navigate the changes your codebase has gone through over time. – sa77 Dec 23 '22 at 03:20
2

git checkout create

git rebase origin master

This will take the changes on your branch and apply them on top of the current master branch, and your branch will be updated to point to the result. In other words, master will be merged into create.

Zarwan
  • 5,537
  • 4
  • 30
  • 48