1

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?

das-g
  • 9,718
  • 4
  • 38
  • 80
NIlesh Sharma
  • 5,445
  • 6
  • 36
  • 53
  • I'm not sure if I followed you, but if you want to put your commit on top of what the others pushed to origin/branch you can pull with --rebase option. – fgp Aug 28 '12 at 13:54

3 Answers3

5

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

eis
  • 51,991
  • 13
  • 150
  • 199
4

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.
Bananeweizen
  • 21,797
  • 8
  • 68
  • 88
  • 1
    or just use `git pull --rebase` as explained here: http://marketblog.envato.com/general/rebasing-merge-commits-in-git/ – Rodion V Aug 22 '15 at 21:04
3

All you need is git pull --rebase

Rodion V
  • 321
  • 3
  • 10