DEV Community

Maxine
Maxine

Posted on

Stop Struggling with Merging Branches and Use these Git Commands instead

Stop Conflicting Merge Requests and Use These Commands instead ⤵️

-Xtheirs

Using the -Xtheirs flag when running git rebase or git pull, will favor the incoming changes from the branch you are rebasing/pulling from. Doing this means you accept any incoming changes from the branch you are rebasing/pulling off of. Say goodbye to going through to accept them all manually. Here is an example of how the command can be used:

git rebase -Xtheirs <branch you are rebasing/accepting changes>
Enter fullscreen mode Exit fullscreen mode

or

git pull origin <branch you are rebasing/accepting changes> -Xtheirs
Enter fullscreen mode Exit fullscreen mode

-Xours

Similarly using the -Xours flag when running git rebase or git pull, will favor the YOUR changes when rebasing with another branch. Doing this means you are accepting and keeping YOUR changes while pulling or rebasing from another branch. Here is an example of how the command can be used:

git rebase -Xours <branch you are rebasing/accepting changes>
Enter fullscreen mode Exit fullscreen mode

or

git pull origin <branch you are rebasing/accepting changes> -Xours
Enter fullscreen mode Exit fullscreen mode

Conclusion

I hope this tiny tutorial helps make the tedious process of merging branches can be a tad bit easier. Let me know what you think of these commands!🌟

Top comments (0)