vani vani - 1 year ago 168
Git Question

Git clone and overwrite local repository

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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download