Reputation: 6057
I made a new branch called feature1
from the main develop
branch a month ago.
⇒ git branch
develop
* feature1
I've been working on feature1
for a month now and a lot of changes have been pushed to develop
.
How can I update my current branch feature1
with the latest commits from develop
?
I DO NOT want to checkout master
and merge my feature1
branch into it. Neither do I want to use git cherry-pick
to manually move commits from develop
to feature1
.
How would I go about doing this?
Upvotes: 149
Views: 297738
Reputation: 7094
First you need to update your develop branch, then checkout your feature and merge/rebase it.
git checkout develop
git pull
git checkout feature/myfeature
Now you can decide between running:
git merge develop
git rebase develop
merge
: keeps all commits history from your branch, and that is important if your partial commits have a lot of content that can be interesting to keep.
rebase
: Rebase means moving (involves a delete, but first it copies) the commit history from feature
and instead have the history from develop
or best said "reapplied" on top of the freshly pulled develop, just as if they were made on top of the fresh develop from the start. this option is obligatory in some teams.
When you are ready you can push to your own branch (for example for a pull request)
git push origin feature/myfeature
Upvotes: 126
Reputation: 537
If you are looking for a simple solution to this, just do below:
Change to feature1
branch (if not already on it):
git checkout feature1
Get the lates t changes from the remote:
git fetch origin
Merge develop
into feature1
:
git merge origin/develop
This pulls in the latest commits from develop
into your feature1
branch. If there are conflicting changes, resolve any merge conflicts.
Or, you can do rebasing if you want a cleaner history without a merge commit.
Rebase feature1
onto develop
:
git rebase origin/develop
If there are conflicts during the rebase, the process will stop and let you resolve conflicts manually, and then continue the rebase process:
git rebase --continue
Upvotes: 0
Reputation: 4078
In IntelliJ IDEA just follow these steps:
select "Log"
right click on "develop"
click on either
-Merge 'develop' onto 'feature1' (keeps all commits history from your branch)
or
-Rebase 'develop' into 'feature1' (delets the commit history from your branch and instead have the history from develop)
Finally Git push
Upvotes: 0
Reputation: 399
I have found the solution. Checkout the previous branch and pull the new branch https://stackoverflow.com/a/71306254/17779236
Upvotes: 0
Reputation: 4493
If you don't want that the develop
head and the feature1
head will merge both into feature1
, but instead you want keeping each branch head distinct while "updating" feature1
branch with the latest edit from develop
, use no fast-forward:
git pull
git co feature1
git pull
git merge --no-ff develop
git push
I personally try to use --no-ff
everytime I perform a merge because in my opinion it keeps the history quite clean.
Upvotes: 4
Reputation: 12685
This use case is very helpful to keep updated your PR branch. Firstly, I would recommend you to fetch first your remote changes, i.e. git fetch
and then merge or rebase from develop
, but from the remote one, e.g.
git rebase -i origin/develop
or
git merge origin/develop
This way you will update your PR branch without going back and forth between branches.
Upvotes: 7
Reputation: 1466
$ git checkout <another-branch> <path-to-file> [<one-more-file> ...]
$ git status
$ git commit -m "Merged file from another branch"
Upvotes: -1
Reputation: 19283
To avoid having the commits from develop by using a simple merge, i've found that the easier (less techier) way to do it is specially if you already pushed:
feature1_b
feature1
to feature1_b
feature1
So when you do your PR of feature1_b
into develop, it will only have your new changes and not the whole history of commits.
If you haven't pushed then @stackdave's answer is a good answer.
Upvotes: 0
Reputation: 9
BRANCHS:
DEV ====> develop
feature1 ====> working
STEP 1 GIT SENDING FROM THE SITE
checks the branch you're syncing
git status
add files for the commit
git add .
commits with a description
git commit -m "COMMENT"
send to the branch that you are synchronized
git push
STEP 2 SYNCHRONIZING THE UPDATED WORK BRANCH WITH DEV (development) - synchronizes the working branch with the development branch (updates the development branch)
synchronize with the remote and switch to the DEV branch
git checkout DEV
request to merge the branch that you are syncing with the feature1 branch
git merge feature1
Merge the current branch with the feature1 branch
git push
STEP 3 GIT FINDING THE REMOTE - Update the working branch from the updated development branch
connects to the reference branch
git checkout DEV
Search changes
git pull
Syncs with your work branch
git checkout feature1
request to merge the branch that you are synchronized with the DEV branch
git merge DEV
Merge the current branch with the DEV branch
git push
Upvotes: 0
Reputation: 15189
You just merge develop to feature1:
git checkout feature1
git merge develop
There is no need to involve another branch such as master.
Upvotes: 199