Search code examples
gitgithubgit-rebase

GIT: Rease local master with local branch


I have local branch (development) but I want merge my changes to master.

I tried the following:

form my development branch:

git rebase origin/master

But what happened my development branch lost my changes and I had to reset my development branch.

How can I rebase my master branch with development branch?


Solution

  • If you are on your development branch (let's say it's called dev):

    git checkout dev
    

    And you rebase it on the remote master branch:

    git rebase origin/master
    

    This should result your changes on top of the latest change in origin/master. Note that depending on your local activity, master may not have the same content as origin/master so make sure you are rebasing on top of the correct branch.

    This shouldn't cause any changes to be lost, although depending on the changes involved it can result in conflicts that need to be resolved manually.

    If you aren't sure you're doing the right thing, remember that you can always test things out on a new branch. E.g., to checkout a new branch named testbranch that is identical to your dev branch:

    git checkout -b testbranch dev
    

    Now you can play with rebase without making any changes to your dev branch.