0

I want to overide my local project with an remote repository. So before I do something unedible, should I "just" do:

cd path/to/project

and then

git pull https://github.com/someuser/someproject.git

??

ST80
  • 3,565
  • 16
  • 64
  • 124
  • https://stackoverflow.com/questions/1125968/how-do-i-force-git-pull-to-overwrite-local-files – Alexan Mar 19 '19 at 14:30
  • Possible duplicate of [Reset local repository branch to be just like remote repository HEAD](https://stackoverflow.com/questions/1628088/reset-local-repository-branch-to-be-just-like-remote-repository-head) – phd Mar 19 '19 at 15:56
  • https://stackoverflow.com/search?q=%5Bgit%5D+local+repository+exactly+like+remote – phd Mar 19 '19 at 15:57

3 Answers3

4

Probably git reset --hard origin/HEAD is what you need. It will revert all changes not pushed to remote repository.

Mikhail Vladimirov
  • 13,572
  • 1
  • 38
  • 40
  • doesn't it need to be `origin/HEAD`? The OP seems to be asking how to ignore local changes and "overwrite" them with the upstream repo? – bitoiu Mar 19 '19 at 15:25
  • Exactly what I was looking for! :-) Thanks! – ST80 Mar 19 '19 at 22:26
0

When you say override, this local project will be identical to remote repository?

If so,

How about go to a directory where you want to put it so cd path/to

Then,

git clone https://github.com/someuser/someproject.git

which will bring someproject into path/to. Fresh and new!

spinyBabbler
  • 392
  • 5
  • 19
0

There are some things you should check. So if you try to change your repo to a new one. You can go to your .git/config and change the path to the new repository. The repositories have to be identical.

Ich you have changed you can pull new changes from the new one with:

git pull origin branchname

Otherwise if you have local changes then you have to reset your branch first and then pull.

git reset --hard HEAD^ 

which reverts your changes to the last commit.

René Höhle
  • 26,716
  • 22
  • 73
  • 82