Introduction to the
background
SourceTree should be familiar to those who have used Git version management. Git is a cross-platform GUI tool. The interface is very good, and the function is also very powerful. Below xiaobian for SourceTree to do a small summary, I hope you like!
Download for Mac OSX or Windows
This software is free, but requires registration, login authorization; The login and authorization steps are fine, but for registration you need scientific Internet access to register.
There are a number of editors that can be used for Git commit Code, including merge Code, etc. I have written an article about how to commit Code in Visual Studio Code. There are also many git commit plug-ins in VS Code. But SourceTree was found to be a little more powerful and professional.
Add the warehouse
Clone warehouse
The new branch
Creating a new remote branch on GitHub or GitLab is easy. You just need to specify which side to clone it from.
⚡ It is important to note that the new remote branch may not be displayed on SourceTree. In this case, we can pull from origin again.
Check out the branch
When developing locally, of course, you need to create a local branch corresponding to a remote branch, and the SourceTree checkout function is very powerful. A check out branch is the same as creating a local branch that is synchronized with the remote code. This is very common when iterating on a project’s functionality. You can commit different functionality to different branches without affecting each other.
In the origin to find the remote branch to check out, right-click to check out
You can change the local branch name, but it is recommended to keep it consistent for easy lookup
You can also double click on a branch to switch
The submission process
Let me give you the general idea
The commit process is very simple, it goes like this: first save the file to commit, commit, pull the branch code (in this case, pull the code written by others), resolve the conflict (you changed the same place with others), then commit, and finally push it up. Simple!!!!
Temporary code
Check the check box in for temporary file to temporarily save. Temporary means that THE file I have here is ready to be submitted.
submit
Resolve the conflict
Conflict resolution is not handled very well by this tool, but it is recommended to use the editor to resolve the conflict. Vs Code resolves conflicts
Roll back to submit
Sometimes we submit code that has problems and needs to be rolled back. Right-click a change (in the case of sourcetree, a node) and select Rollback Commit.
conclusion
The submission process is clear, but remember to pull before pushing.
Manipulation of the branch
Switch branch
Switching branches is easy. Double-click a branch under the branch TAB
⚡ Please note that you should try to commit the branch code before switching, otherwise you will report an error if the code conflicts
Merge branches (merge code)
Merge A branch in A remote branch to merge B remote branch code, do A include B effect, the general process is: (1) first in the local switch to A branch, (2) merge B branch code, (3) conflict if there is conflict, (4) commit to complete the merge.
Merge [email protected] branch code: first pull [email protected] to master
Method one:
If there are conflicting files after the pull, you need to resolve the conflicts locally (if there are too many conflicts, it is recommended to use the editor to resolve the conflicts).
Resolve the conflict
Commit (consistent with normal commit process)
Method 2:
Point merge branch
After the merge, you can also locally compare what files were added and what changes were made (conflict resolution conflict, recommend using editor to resolve conflicts).
Q&A
1. Each time I use sourceTree to pull the code, I need to enter the password. How do I solve this problem?
As shown in the figure:
Solution 1:
Just spell gitnam@ on each Git or Gitlab repository, as shown in the figure below:
Solution 2:
Delete the git branch from your network and try again!