This article has participated in the activity of “New person creation Ceremony”, and started the road of digging gold creation together.

preface

Git, a well-known distributed version control system, should be used as a program must master skills, but in order to be more efficient, most people have not used git command line operation, everyone is using a variety of Git visualization tools, Sourcetree is a good git visualization tool.

This article introduces git visualization tool Sourcetree operation details, including all kinds of Git branch management operations, git various conflict solutions (merge conflict, pull conflict, forget to pull commit, git cancel merge operation) solutions, so that you can fully master the use of Git.

Import warehouse

First of all, we need to know how to pull our own warehouse to the local.

Here, take the code cloud as an example to find the corresponding source path /URL:

Copy and then go to Sourcetree:

Update version operation

Modify the

When you make changes to your local code, an unstored file will appear:

pull

When someone else updates your code and you don’t pull it locally, the pull will light up and you can click to pull someone else’s code:

submit

When you modify the code, you need to commit the action:

Branch operation

Remote and local branches

Branches are divided into branches from remote repositories, and branches that you pull to the local

Switch branch

Note that if there is a local modification of the code that has not been submitted, note that the modification, the new content is generally not affected, switching will report an error.

You can switch through the commit operation first.

But the question is, what if you’re halfway through the code and you don’t want to commit but you have to switch branches? See below.

storage

You can leave the changes in place for a while, clear the status area, and switch branches. When you switch back, you can apply the cache and change back to the original state.

When we switch out and cut back, we apply it

Delete the branch

Note that deleting the current branch requires switching to another branch. You cannot delete your current branch.

Get remote branches

I have deleted the local dev branch and want to obtain the remote dev branch to the local dev branch.

It is important to note that checking out branches will automatically switch the checked out branches. If you have local code that has not been modified, be careful firstsubmitOr tostorageOh.

Create a new branch

For example, if we want to create a test version of the branch, all update operations will be done on the test version, if there is no problem and then merge to the main branch, how to create?

It’s still a check-out operation, so be aware of local uncommitted code issues as well.

Merge branch content

We commit code on the Test test branch, and we want to merge it into the master branch.

First we cut back to the main branch:

conflict

Merge conflicts

To test for collisions, we will first create and submit a simple content on the master, annotated 111:

Next we cut the test branch and submit a comment 222 in the same place:

Add test to master branch and add test to master branch.

We can see two different versions of the state, conflicting content:

Choose what you want to keep. If it’s my version, keep //111. If it’s someone else’s, keep //222.

But here we merge test, and test only changes this, so if we merge my version, even though we merge it, it doesn’t make any sense, our master branch doesn’t change anything.

However, this will not happen in the actual project, and we must decide what to keep according to the needs. For example, test added other functions in addition to the comment that conflicted with ours. Although we did not adopt the modification of the comment, we merged the new functions.

The merged test branch is not affected in any way by the merge operation, and the content is not changed. Our merge operation is just to give the master branch access to the updated code on Test.

Commit conflict without pulling

This is what happens when people develop.

If the code does not conflict, and you are not modifying the code on the same page, then the order of the pull and submit does not affect the content of the code.

For example, if someone creates a new page, you don’t pull it down, you modify the content of the original page and submit it directly.

An error. There is this state that cannot be pushed up.

Take your time, just make sure you don’t commit your errors to remote

Remember, at work, it's better to lose your code than overwrite someone else's

It’s really easy, let’s just go back to what we submitted before.

Then pull and then commit.

If we pull first and then commit, the pull first error is reported, usually the last error: the pull code conflicts with the local modification code, as shown in the next section.

The pull code conflicts with the local modification code

Let’s say someone else changes the comment to 333, but when you modify the code locally, the comment changes to 777.

Now you want to submit, pull first and then submit.

Pull out when the report is wrong, dead or alive pull down, how many times also not good.

At this point we submit and then pull.

Then it tells you where the conflict is, and we choose which one to keep. See merge conflict resolution above.

Unmerge operation

If oneself merges the content that does not want merges, want to cancel merges an operation, how to undertake?

In this case, we select the previous commit from the master and reset the branch to this commit.

Turn on forced push.

Ignore submit and pull and choose push directly.

Remove and discard all changes.

Then you notice that the merge operation has disappeared.

Stern said

Even if you don’t know git commands at all, using Sourcetree can solve 95% of your daily Git version control problems. Give it a thumbs up if you find it useful