Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yehudamakarov/5c3f0869e246b6905ead51fad8816b40 to your computer and use it in GitHub Desktop.
Save yehudamakarov/5c3f0869e246b6905ead51fad8816b40 to your computer and use it in GitHub Desktop.
[Git Commands]

The problem is that it's risky, because your local changes are seen by git as diffs relative to the current branch tip, but those diffs may not be applicable to the other branch. For instance if you added a line after an existing line, and that line doesn't exist on the other branch, git won't know what to do From the command line you can do git checkout -m branch which attempts a "merge" algorithm, which may work, or else give you a mess of merge conflict markers Otherwise you can stash your changes, and pop them back later git stash (...later...) git stash pop (git stash pop can result in merge conflicts if you aren't in the same state your were when you stashed it. If so you get the merge conflicts to resolve, and the stash remains on the stack too.) The third option is to erase your changes. You can do that from the command line with git checkout. git checkout -p will prompt you before reverting each change, so you can be sure you're not throwing away anything important.

I think (not sure) git checkout <BRANCH> will tell you which files have potential conflicts, so you can just git checkout the changes in those files, however it can still be messy. In particular you have to think about bringing the local changes back to the original branch later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment