In Git, during a merge, is there a way that we can tell git to discard local changes in case of a conflict and apply the changes from the merged branch?
I mean if there
It sounds like you want to read about the merge strategies 'theirs' and 'ours'. When merging you can specify that either your current branch (ours) or the remote branch (theirs) is the correct one.
If you want to ignore all local changes, and an additional merge commit you want to just move your branch to the remote HEAD.
git log --oneline origin/master
# assume the first sha is bbdfa17
git reset --hard bbdfa17
Now you are at the tip of the tree with no merge commits.
Before trying to merge, you can discard the local changes yourself git reset --hard HEAD
.
You can replace HEAD
by whatever commit hash you want.
This will bring you the the clean state of the commit you're actually on, and you'd lose all your changes.
If you want to keep them, you can stash them before with git stash
, or move them to another branch:
git checkout -b new_branch
git add .
git commit -m "My awesome commit"
git checkout - # will bring you back to the last branch you were in