abbas
abbas

Reputation: 255

How to update my branch when I already made some changes

I created a branch from master before updating it. I made some changes on the branch and I committed and then pushed the branch. After pushing I realized the branch I was working on was not created from updated master branch. My question now is, how possibly can I move those changes to a branch I create from updated master branch.

Upvotes: 1

Views: 1990

Answers (3)

Vikash
Vikash

Reputation: 56

By your question i got , that the branch you have created and pushed is behind master branch and that changes you want to pull in in to the branch that you have created and pushed ? Right if yes then

git checkout master
git pull
git log 

#Take the latest commit id from log and rebase it to the branch that you have created and pushed

git checkout <branch>
git rebase <Commit-id>
git push 

Please let me know if it worked or i understood your question properly or not.

Upvotes: 0

Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391336

The simplest way to solve this would be to merge an updated master into your branch.

Let's take the steps.

You had this:

             master
               v
*----*----*----*

Then you did this:

             master
               v
*----*----*----*
                \
                 *---*---*
                         ^
                       branch

In reality you had this:

             master   origin/master
               v           v
*----*----*----*---*---*---*
                \
                 *---*---*
                         ^
                       branch

The simplest way would be to update master, then merge it into your branch, using these commands:

git checkout master
git pull
git checkout branch
git merge master

This would give you this:

                         master
                      origin/master
                           v
*----*----*----*---*---*---*
                \           \
                 *---*---*---*
                             ^
                           branch

If you instead really need your branch to be based on the updated master, then instead of merging master into your branch you have to rebase your branch on top of master, using these commands:

git checkout master
git pull                      ;; the first two are the same as above, to update
git checkout branch
git rebase master

These commands would give you this result:

                         master
                      origin/master
                           v
*----*----*----*---*---*---*
                            \
                             *---*---*
                                     ^
                                   branch

Upvotes: 4

Sandesh Mankar
Sandesh Mankar

Reputation: 699

Step 1. Pull from master Branch and follow step 2.

Step 2. first, you create a new branch.

git branch <BranchName>
git checkout <BranchName>
git add -a -m "commt name"
git push 

and then create pull request from to Master.

Done

Upvotes: 1

Related Questions