swati
swati

Reputation: 1267

Git - reset local changes

I have done some local changes in code stored in Git repo. I don't need these changes anymore, so I would like to discard them and get a clean copy from github.

When I did a Git pull it gave me a merge conflict error.

So, I did

git reset --hard

but that did not help. I also tried

git stash

but still when I try pull from github, it does not allow me to do so.

Can someone please suggest what would be the best approach to get the latest code from github. Should I just delete the local files and then do a git pull?

Upvotes: 3

Views: 4853

Answers (4)

If you want to leave out all your local changes and get only those from github you can just delete your .git folder and reinitialize it, like that :

rm -rf .git
git init
git remote add origin http://yourGithubUrl.com
git pull

Upvotes: 0

AgentAntelope
AgentAntelope

Reputation: 41

I would do:

git reset --hard {remote_name_here}/{branch_name_here}

Upvotes: 2

Gene Olson
Gene Olson

Reputation: 930

Try:

git checkout -f

For a great discussion of the differences between git reset and git checkout, see:

https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified#_git_reset

Upvotes: 1

Kevin Grosgojat
Kevin Grosgojat

Reputation: 1379

If you just want to get the latest code pushed on remote, you can do that.

rm -rf ./gitProject

git clone yourRemoteRepo

Upvotes: 0

Related Questions