KawaiKx
KawaiKx

Reputation: 9910

git pull rebase while keeping remote on the top

I have a local repo with commits A B C and remote repo with commits D E F. there is nothing common in their histories.

I want a pull remote commits and put them on the top of local commits so that finally I have: A B C D E F with F being HEAD

I tried git pull --rebase but it puts local on the top: D E F A B C

How can get remote on the top of local with repo ignoring their different histories?

Upvotes: 0

Views: 1007

Answers (2)

danglingpointer
danglingpointer

Reputation: 4920

What I can infer from your case, let's assume the following history exists and the current branch is "local":

      A---B---C local
     /
D---E---F <master/remote>

You can perform the following two things.

From this point, the result of either of the following commands: you can checkout the branch and rebase the remote on to the branch.

git rebase master
git rebase master local_branch

              A'--B'--C' topic
             /
    D---E---F master

NOTE: The latter form is just a short-hand of git checkout topic followed by git rebase master. When rebase exits topic will remain the checked-out branch.

Upvotes: 0

ian
ian

Reputation: 1171

git pull --rebase is the combination of git fetch and git rebase origin/<branch> of course it does it that way because you can not push your changes below changes already on the server, without rewriting the server history and therefore brake everyone else's branches.

If you really need to do this:

  1. git checkout -b <new> origin/<branch> create new branch with D E F
  2. git rebase <branch> rebase onto A B C

Upvotes: 2

Related Questions