The most common cause of merge conflicts happens when another user changes the same file that you just modified. It can happen during pull from a remote repository (or when merging branches).
git checkout --theirs conflicted_file.txtgit checkout --ours conflicted_file.txt=> You still have to git add and git commit after this
<<<<<<< HEAD
local version (ours)
=======
remote version (theirs)
>>>>>>> [remote version (commit#)]
=> You still have to git add and git commit after this
During this process, if you want to roll back to the situation before you started the merge: git merge --abort
NOTE: By doing a pull before committing, you can avoid a lot of git conflicts. Your git workflow should therefore be:
git addgit pullcommit -m "descriptive message"git pullgit pushContinuing with the dessert example we used in the first part of this tutorial, we now have on our local machine
adapted from https://www.atlassian.com/git/tutorials/git-merge
What are branches? Well in fact nothing new, as the master is a branch. A branch represents an independent line of development, parallel to the master (branch).
Why should I use branches? For 2 main reasons:
Few commands to deal with branches:
git branch Will list the existing branchesgit branch myBranchName Will create a new branch with the name myBranchNamegit checkout myBranchName Will switch to the branch myBranchName In a rush? create a new branch and switch to it directly:
git checkout -b branchName
Want to switch back to master?
git checkout master
=> Once you have switched to your branch, all the rest of the git workflow stays the same (git add, commit, pull, push)
Done with your branch? Want to merge your new - ready for prime time - script to the master?
git checkout mastergit pull origin mastergit merge myBranchNamegit branch -d myBranchName