NIlesh Sharma
NIlesh Sharma

Reputation: 5655

With Git, how can I pull, but without causing a merge?

I have created a new commit, but forgot to pull before that. (I should have used git stashand than git pull.) Now if I git pull, I get an additional commit "merge origin/<branch> to <branch>" (Some commits have already been pushed by some other colleagues.), which I don't want.

Is there any way to do git pull without merging?

Upvotes: 1

Views: 2950

Answers (3)

Rodion V
Rodion V

Reputation: 331

All you need is git pull --rebase

Upvotes: 3

Bananeweizen
Bananeweizen

Reputation: 22070

If you already did that commit accidentially, then follow this workflow:

  • Create a new branch from the current branch (basically for making a "safety copy" of your commit).
  • Reset your current branch to the commit before your commit ("deleting" the commit).
  • Pull.
  • Cherry-pick your commit from the backup branch to your current branch, delete the backup branch afterwards.

Upvotes: 4

eis
eis

Reputation: 53482

git pull is essentially git fetch followed by git merge, so if you want a pull without the merge, just do git fetch.

Upvotes: 4

Related Questions