Search code examples
gitpull

Git: Update repository without losing commits


I'm a novice in git. I'm working on on project X. I have the following problem:

Remote

Origin -> A - B - C

BranchX -> A - B - D

Local

Origin -> A - B

BranchX -> A - B - D

How do I get commit C to BranchX in my local such that the local repo looks like this:

Local

Origin -> A - B - C

BranchX -> A - B - C - D


Solution

  • First you make sure you have BranchX checked out

    git checkout BranchX
    

    then update your local Origin branch from remote

    git fetch origin Origin:Origin
    

    lastly rebase your BranchX onto the Origin branch

    git rebase Origin