I've tried searching for an elegant way (i.e. that doesn't involve deleting the local directory and cloning again) to update a severely stale local repo from a remote repo using git, but haven't found a good answer. The command I'm looking for would basically resolve any conflict by using whatever the remote repo says and deleting local files if need be (in case they no longer exist in the remote repo) and ignoring any and all chancges I might've made to tracked files.
Asked
Active
Viewed 361 times
2 Answers
1
You could:
- delete all local branches (see "Delete all local git branches")
- recreate the local branches, tracking the remote branching of your remote repo: see "Track all remote git branches as local branches"
- cleanup the old commits no longer referenced by your new branches: "How to remove unneeded git commits?"
So you don't have to deal with "merge conflicts": it is sort of a global reset (proceed with caution if you had any work you would like to keep, which doesn't seem to be the case from your question).
The OP Syrahn went for a simpler way:
at that point I just
rm -Rf
the dir and clone from scratch.
Git really needs a--theirs --all --force
type of thing.
Note that there are ways to emulate "theirs" option, even if "Git merge -s theirs: Simply?" explains why it isn't very visible: see "git command for making one branch like another"
-
ugh. That's a lot of work for what can be done essentially in one command in the svn world :/ – rdodev Oct 04 '12 at 23:33
-
I didn't actually try, at that point I just rm -Rf the dir and clone from scratch. Git really needs a --theirs --all --force type of thing. – rdodev Oct 06 '12 at 09:40
-
@Syrahn interesting. I have edited the answer to include your solution, and added links to ways of making a branch looks like another, including all the ways to simulate the `--theirs` option. – VonC Oct 06 '12 at 19:49
1
Try using these commands:
git fetch
git reset --hard origin/master
This will force your local branch to match the branch on the remote while throwing away any changes. Note however you will need to execute the second step for each branch.

Adam
- 2,762
- 1
- 30
- 32