1. Create and merge branches
1. Create a branch
Create a dev branch, then switch to the dev branch
git checkout -b dev
1
Note: The git checkout command plus the -b parameter means to create and switch, which is equivalent to the following two commands
git branch dev
git checkout dev
2. View the current branch
List all branches, the current branch will be preceded by a *
git branch
3. Modify and submit readme.txt
Modify the content of readme.txt
Add to the staging area and submit to the local warehouse
git add readme.txt
git commit -m “branch test”
4. Switch branches and merge branches
Next, we switch to master first, and then merge the results on the dev branch into the master branch
git checkout master
git merge dev
5. Delete branch
After we have merged the branch, we can delete the sub-branch. Next, we delete the dev branch and check the current branch situation.
git branch -d dev
git branch
2. Resolving conflicts
1. Create a branch and modify readme.txt
We create the feature1 branch and modify the last line of the readme.txt document
git checkout -b feature1
git branch
2. Submit and switch branches
Next, we add and submit readme.txt in the feature1 branch, and then switch to the master main branch
git add readme.txt
git commit -m “AND simple”
git checkout master
3. Modify txt and submit it on the master main branch
Modify the last line of txt and submit it on the master main branch
git add readme.txt
git commit -m “& simple”
4. Merge branches
Now feature1 and master each have new branches. At this time, Git cannot perform “quick merge”, and can only try to merge their respective changes, but this merge may conflict
git merge feature1
The eadme.me file contains conflicts and must be resolved manually before submitting
Using git status can also tell us about conflicting files
git status
5. View the content of readme.txt
cat readme.txt
1
Git marks the content of different branches with <<<<<<<, =======, >>>>>>>
6. Modify txt and submit
Modify the content of the readme.txt text and submit again
git add readme.txt
The branch situation at this time:
7. View the content and delete the branch
Finally, we check the content of the document, check the current branch and delete the feature1 branch
cat readme.txt
git branch
git branch -d feature