brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git checkout with ours or theirs picks one side of a conflicted file

Git
~/tips/tip-git-checkout-ours-theirs-conflict

git checkout --theirs package-lock.json

Resolves a whole conflicted file by taking your version or the incoming one.

Some conflicts aren’t worth resolving line by line. For a generated file or a lock file, I just want one side complete and then regenerate.

git checkout --theirs package-lock.json
git add package-lock.json

During a merge, --ours is the version on your current branch and --theirs is the version from the branch you’re merging in. The command replaces the conflicted file in your working tree with that version. Then git add marks it as resolved. git restore --theirs does the same if you prefer the newer command.

For a lock file, I’d follow up by running the package manager once more, so the result matches both sides’ dependencies.

If you change your mind, git checkout -m package-lock.json brings back the file with conflict markers so you can start over.

The big trap is a rebase. There, the meaning flips: git replays your commits on top of the other branch, so --ours is the branch you’re rebasing onto and --theirs is your own work. Look at the result with git diff --cached before continuing, instead of trusting the word. And remember this takes the whole file. Any change from the other side in that file is gone, not only the conflicting lines.

Further reading: git-checkout documentation, git-restore documentation

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link