Git Branching And Merging
git branch branchName // create a new branch git checkout branchName // switch to the new branch get checkout master // switch back to the main branch git branch // display a list of branches git branch -a // List all of the branches locally and one the remote repository git branch --merge // see if the merge was successful git branch -d branchName // delete a branch git merge sourceBranchName If we only want to download and inspect remote changes (before integrating them), we can use 'git fetch'. Later, we can integrate the downloaded changes via 'git merge'. Before we merge, we should make sure that we are using the destination branch. We can use 'git status' to determine the branch that we are currently using. If we want to merge the change from sourceBranchName to the main branch (master), use 'git checkout master' to switch to the master branch, and then run 'git merge sourceBranchName' to merge changes from sourceBranchName to master. When using 'git commit -a' to commit changes, we can skip the staging step, and changes to the files that are being tracked will be automatically included in the commit. After we resolve the conflict, we can use 'git commit -a' to commit. There is no separate 'resolved' command to mark the file as resolved. Beside manually resolving the file, once we get a conflict, we can use the 'git mergetool' to help us resolve the conflict. We should get a merge tool such as WinMerge and configure Git to use it. git fetch origin // Get all changes that was pushed or committed to origin // since you last fetch from it. Fetching will not merge these changes // into your work. You will have to merge these changes manually. git pull origin // Automatically fetch and merge all changes from origin. When you are ready, commit your work with 'git commit -a' or 'git commit', and then you can use 'git push origin master'. // Push changes to the master branch on the origin repository. git pull /home/bob/myrepo master The above command pull changes from the repository at /home/bob/myrepo. This merge the changes from Bob's master branch into the current working copy.
page revision: 6, last edited: 25 Dec 2016 23:22