You are on page 1of 4

Accidentally pulled a remote branch into different local branch — how to undo the pull?

: git 17/09/16 15:02

MY SUBREDDITS FRONT - ALL - RANDOM | ASKREDDIT - FUNNY - PICS - GIFS - TODAYILEARNED - VIDEOS - NEWS - GAMING - WORLDNEWS
MORE » -

GIT comments Want to join? Log in or sign up in seconds. | English

search
This is an archived post. You won't be able to vote
or comment.
this post was submitted on 20 Jan 2015

Accidentally pulled a remote branch into 8 points (100% upvoted)


8 different local branch — how to undo the shortlink: https://redd.it/2t0kx0

pull? (self.git)
submitted 1 year ago by flitterio
username password
My local repo has the master branch
currently checked out. I accidentally did remember me reset password login
git pull origin otherbranch and Git
happily merged otherbranch into my
master , which I didn't intend. Now I have
lots of merge conflicts in many files due to
significant differences between the two
branches.
How can I undo this? I tried
git checkout master but it refuses,
saying that several files need merging.

12 comments share

all 12 comments
sorted by: best
[–] flitterio [S] 7 points 1 year ago

I think git reset --hard followed by Submit a new link


git checkout master fixes this. Found this
buried in the help for git reset :
Submit a new text post
Undo a merge or pull
git
$ git pull (1 subscribe 11,992 readers
) ~2 users here now
Auto-merging nitfol From its website:
CONFLICT (content): Merge conflict in Git is a free and open source distributed
nitfol version control system designed to handle
Automatic merge failed; fix conflicts everything from small to very large projects
with speed and efficiency.
and then commit the result.
Git is not the same as GitHub. GitHub did not
$ git reset --hard (2 create Git. Git is not an acronym or initialism:
) please write git or Git, but not GIT.
$ git pull . topic/branch (3
Documentation
)
Pro Git

https://www.reddit.com/r/git/comments/2t0kx0/accidentally_pulled_a_remote_branch_into/ Page 1 of 4
Accidentally pulled a remote branch into different local branch — how to undo the pull? : git 17/09/16 15:02

Updating from 41223... to 13134... Git Ready


Git Reference
Fast-forward Git Magic
$ git reset --hard ORIG_HEAD (4 Git for Computer Scientists
) A Visual Git Reference
Git Primer
Git Immersion
1. Try to update from the upstream resu Think Like a Git
lted in a lot of conflicts; Git Workflows
Git on Stack Overflow
you were not ready to spend a lot of Getting Git Right
time merging right now, so
you decide to do that later. Graphical Clients
GitHub (Win)
GitHub (Mac)
2. "pull" has not made merge commit, so SourceTree (Win, Mac)
"git reset --hard" which is SmartGit (Win, Mac, Linux)
a synonym for "git reset --hard HEAD GitX (Mac)
Tower (Mac)
" clears the mess from the Git Extensions (Win)
index file and the working tree. TortoiseGit (Win)
GitEye (Win, Mac, Linux)
GitKraken (Win, Mac, Linux)
3. Merge a topic branch into the curren Working Copy (iOS)
t branch, which resulted in Git2Go (iOS)
a fast-forward.
Code Hosting
GitHub
4. But you decided that the topic branc GitLab
h is not ready for public Bitbucket
consumption yet. "pull" or "merge" a Codebase
Bonobo Git Server
lways leaves the original Gogs
tip of the current branch in ORIG_HE a community for 8 years
AD, so resetting hard to it
brings your index file and the worki
ng tree back to that state,
and resets the tip of the branch to
that commit.
permalink embed

[–] baldeagleNL 1 point 1 year ago

The key to undoing most things is going back to


a previous commit. This explanation works for a
lot of other stuff as well.
If you pull a branch, a new merge commit is
created. You want to get rid of that commit and
www.trocafone.com
go back to the previous one.
MODERATORS message the moderators
Doing that is easy.
jbcrail
git reset --hard HEAD^ ccharles Magit + CLI + GitLab
about moderation team »
The reset --hard goes back to a state and
removes all changes since than from your file < > discussions in /r/git X

https://www.reddit.com/r/git/comments/2t0kx0/accidentally_pulled_a_remote_branch_into/ Page 2 of 4
Accidentally pulled a remote branch into different local branch — how to undo the pull? : git 17/09/16 15:02

system. Watch out with this command if you 7 points · 3 comments


I have a static blog in a git repo at Gitlab. I
have uncommitted changes, you'll never see
would like to add a new post (create a new
them back! file) on my Android phone. How can I do
that?
The part you want to go back to is the previous
commit, one before the HEAD. This is done by
the HEAD^ part.
I found
[http://stackoverflow.com/questions/4114095/re
vert-to-a-previous-git-commit](this stackoverflow
post) quite useful.
permalink embed

load more comments (8 replies)

[–] u801e 1 point 1 year ago

Run git reflog and check the list of commits. You'll probably see something like:

abcdefg HEAD@{X}: merge origin/otherbranch: ...

You can look a little further down the git reflog output and see the previous commit on the
master branch. The SHA1 that's listed there is the one you want to reset the HEAD of the
master branch to. That is, run

git reset --hard bcdef01

If the SHA1 was bcdef01 for that commit.


permalink embed

More from r/git


new git stash tutorial - stashing work, managing multiple stashes, etc.
19 (atlassian.com)
submitted 5 days ago by hackergirl888
comment share

Git microconference accepted into Linux Plumbers Conference 2016


11 (linuxplumbersconf.org)
submitted 13 hours ago by JoshTriplett
comment share

Build a TensorFlow Image Classifier in 5 Min (youtube.com)


11 submitted 3 days ago by llSourcell
2 comments share

Git – Some bad situations and how I got myself out of them in plain english.
12 (ohshitgit.com)
submitted 4 days ago by arshubham
5 comments share

Ultra simple question that I can't find an answer for: How do I make remote be
9 an exact mirror image of local? (self.git)
submitted 1 day ago * by 1337_n00b
12 comments share

I have a static blog in a git repo at Gitlab. I would like to add a new post
https://www.reddit.com/r/git/comments/2t0kx0/accidentally_pulled_a_remote_branch_into/ Page 3 of 4
Accidentally pulled a remote branch into different local branch — how to undo the pull? : git 17/09/16 15:02

5 (create a new file) on my Android phone. How can I do that? (self.git)


submitted 5 hours ago by Jerry368
3 comments share

git commit -v diff style (self.git)


7 submitted 1 day ago by franconezappa
1 comment share

Any reason not to clone one repo inside another, to avoid submodule horror?
5 (self.git)
submitted 6 days ago by theonlybenji
10 comments share

Slideshow Presentations for Git Developers - GitHub, GitLab, Bitbucket


6 (github.com)
submitted 6 days ago by gitpitch
comment share

Help: .gitattributes ignored when merging (self.git)


5 submitted 6 days ago by simonced
1 comment share

about help apps & tools <3


blog site rules Reddit for iPhone reddit gold
about FAQ Reddit for Android redditgifts
source code wiki mobile website
advertise reddiquette buttons
jobs transparency
contact us

Use of this site constitutes acceptance of our User Agreement and Privacy Policy (updated). © 2016 reddit inc. All rights reserved.
REDDIT and the ALIEN Logo are registered trademarks of reddit inc.

https://www.reddit.com/r/git/comments/2t0kx0/accidentally_pulled_a_remote_branch_into/ Page 4 of 4

You might also like