Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merge updated develop branch into local branch

Tags:

git

git-merge

How do I go about updating a branch that I have checked out, with the updated (which has had a few pull requests merged, after the local branch was branched off of develop) develop branch ? At the moment, if I am on branch_1 with un/committed/pushed changes, I do a

git checkout develop
git pull
git checkout branch_1
git merge develop

Is there a way with lesser steps to achieve what I am after ?

like image 745
happybuddha Avatar asked Apr 23 '18 00:04

happybuddha


People also ask

How do I merge changes from one branch to another locally?

To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.

What happens to local branch after merge?

In a good workflow, the feature branch is deleted once its merged back into master. New branches should be created for each new feature(s) that you work on.

How do I merge changes from one branch to the main?

First we run git checkout master to change the active branch back to the master branch. Then we run the command git merge new-branch to merge the new feature into the master branch. Note: git merge merges the specified branch into the currently active branch.


1 Answers

If you want to update branch_1 via merging, then there is a slightly shorter version of doing this:

git fetch origin
git checkout branch_1
git merge origin/develop

By doing a git fetch, you automatically update the remote tracking branch for develop, which is called origin/develop. Note that the local branch develop would not be updated, but it doesn't matter, because you can merge with the tracking branch.

like image 162
Tim Biegeleisen Avatar answered Oct 19 '22 22:10

Tim Biegeleisen