Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git clone and overwrite local repository

Tags:

git

I would like to have an up to date copy (periodically) of the bitbucket repo on my server, but not sure which git commands I have to issue to avoid potential merge conflicts that can happen with pulls.
The only clean way I can think of is to clone to a tmp dir then copy/overwrite local repo.
But there must be a better way to achieve this?

like image 364
steakoverflow Avatar asked Aug 05 '16 08:08

steakoverflow


People also ask

Does git clone overwrite?

You can also use git force clone to overwrite your history entirely. But be careful. This will destroy your local work.

Does git pull overwrite local?

Just like git push --force allows overwriting remote branches, git fetch --force (or git pull --force ) allows overwriting local branches.


1 Answers

Instead of cloning to a tmp dir and then replacing your local repository with that new clone, you can fetch from the remote and hard-reset your local:

git fetch origin master
git reset --hard origin/master

There won't be merge conflicts, as you're simply taking whatever is in origin/mater.

like image 99
janos Avatar answered Sep 18 '22 11:09

janos