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.txt
git 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 add
git pull
commit -m "descriptive message"
git pull
git push
Continuing with the dessert
example we used in the first part of this tutorial, we now have on our local machine
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 myBranchNameIn 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 master
git pull origin master
git merge myBranchName
git branch -d myBranchName