Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I accept all changes from a remote?

Tags:

git-pull

merge

I'm doing a pull origin some_branch and can see there are a lot of changes. Eventually I don't mind if their erase all mine.

How can I accept them all instead or using mergetool and merge files one by one?

like image 410
e-satis Avatar asked Apr 26 '10 07:04

e-satis


2 Answers

Just:

    git clone $url

Seriously! That's the best way.

You could do all sorts of git reset and git branch commands to move the refs, but the only purpose would be to keep your commits somewhere in your local repository for future reference. If that's the goal, just keep the whole repository as is, and re-clone the origin.

To accept all changes on just one branch, foo:

    git checkout foo
    git fetch origin +refs/heads/foo:refs/remotes/origin/foo
    git reset refs/remotes/origin/foo

foo will now point at the same commit as foo on origin. If you want to blow away the files in your working directory, add --hard to git reset. If you want to merge first, replace fetch with pull.

You may have a bunch of dangling commits in your local repo, which git may clean-up someday, but for awhile you can still access them via the reflog.

like image 175
cdunn2001 Avatar answered Oct 14 '22 16:10

cdunn2001


Or:

git status | grep "both " | cut -f2 | cut -f11 -d" " | xargs git checkout --theirs
git status | grep "both " | cut -f2 | cut -f11 -d" " | xargs git add

which forces accepting all conflicting remote files.

like image 35
Austin Hanson Avatar answered Oct 14 '22 17:10

Austin Hanson