Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”

Author’s other platforms:

| CSDN:blog.csdn.net/qq_4115394…

| the nuggets: juejin. Cn/user / 651387…

| zhihu: www.zhihu.com/people/1024…

| GitHub:github.com/JiangXia-10…

| public no. : 1024 notes

This article is about 3,751 words and takes 10 minutes to read

1, the preface

Git distributed version control system is an integral part of our daily development and greatly improves the efficiency of our collaborative work. The previous article explained how to play Git. In our work, we often need to use Git visual management tools for version control. At present, the popular Git visual management tools on the market include SourceTree, Github Desktop, TortoiseGit and so on. Our company mainly uses SourceTree. This article mainly combined with the daily development work of sourctree some common operations to explain and summarize, to help students who have not used a quick start, I hope to be helpful to everyone!

2, the body

The first, of course, is to explain the Sourcetree download and installation.

For downloads of sourcetree versions:

www.sourcetreeapp.com/download-ar…

It is recommended not to download the latest version, because the new version is sometimes unstable. It is recommended to download the first 1-2 versions of the latest version. I used version 3.4.4 here.

After the download is complete, an executable file of.exe can be directly double-click to install.

During the SourceTree installation, you need to log in using an account. However, the registration or login interface may not be opened at all. As a result, the software cannot be installed normally. In this case, you can solve the problem through the following methods:

Create the file accounts. Json under directory C:\Users\{username}\AppData\Local\Atlassian\SourceTree. Note: {username} needs to be replaced by the login username. For example, my computer path is:

C: \ Users \ \ Administrator \ AppData \ Local \ Atlassian \ SourceTree. The contents of the accounts.json file are as follows:

[ { "$id": "1", "$type": "SourceTree.Api.Host.Identity.Model.IdentityAccount, SourceTree.Api.Host.Identity", "IsDefault": false, "Authenticate": true, "HostInstance": { "$id": "2", "$type": "SourceTree.Host.Atlassianaccount.AtlassianAccountInstance, SourceTree.Host.AtlassianAccount", "Host": { "$id": "3", "$type": "SourceTree.Host.Atlassianaccount.AtlassianAccountHost, SourceTree.Host.AtlassianAccount", "Id": "atlassian account" }, "BaseUrl": "https://id.atlassian.com/" }, "Credentials": { "$id": "4", "$type": "SourceTree.Api.Account.Basic.BasicAuthCredentials, SourceTree.Api.Account.Basic", "Username": "", "Email": null, "AvatarURL": null, "AuthenticationScheme": { "$type": "SourceTree. Api. Account. Basic. BasicAuthAuthenticationScheme, SourceTree. Api. The Basic", "Value" : "username/password", "Name" : "Basic", "Description": "password ", "HeaderValuePrefix": "Basic", "UsernameIsRequired": true}, "Id": "", "EmailHash": null, "DisplayName": null } }, { "$ref": "1" } ]Copy the code

Then restart the software and enter the interface smoothly.

This assumes that you already have Git installed on your local computer. If you don’t have a git installation to use, please refer to the previous article: How to Play Git.

With that in mind, it’s time to configure and use SourceTree!

First we need to add the SSH key in SourceTree. Select option menu in the toolbar of the menu bar,SSH client configuration,SSH secret key: C:\Users\Administrator\.ssh\id_rsa.pub, and then SSH client option: OpenSSH, as shown below:

‍‍‍‍‍‍‍

Now you can Clone the remote code, using GitHub as an example and gitee as an example:

Open github and find the source code you need to clone. Select SSH for code and copy the address. Here you need to configure the github key as well.

Then open sourcetree and clone the project locally:

As can be seen from the above, the default storage location of each Clone project is always in disk C. If it is kept in disk C all the time, the system disk will become smaller and smaller, and the computer will become more and more jammed. It is also troublesome to change the project path every time, so we can set a default storage location for the project:

Click Tools –> Options –> General –> Find the Project directory and set the Clone project’s default storage location:

Collaborative development often involves creating different branches for different versions or features, and then merging versions.

1. Create a branch:

Dev-1017 dev-1017 dev-1017 dev-1017 dev-1017 dev-1017 dev-1017 dev-1017 dev-1017 dev-1017 dev-1017 dev-1017 dev-1017 dev-1017 dev-1017 dev-1017

Because the default check out was selected earlier, the branch is automatically checked out:

If you need to switch to another branch, you can directly double-click the corresponding branch to switch to this branch, on the premise that the branch must be checked out from the remote first:

More than one person in different branches, after the completion of development need to merge branches version then send measurement, such as by right-clicking on the main branch, select merge just created dev – 1017 new branch to the current branch can be merged, the merge code before we all need to need to merge branches pull to the latest status to avoid covering other people’s code, Or missing code:

When the code is complete, you need to submit the code:

Submit the modified code to the staging area:

If we find that a file has been changed incorrectly, we can right-click the file and select Discard to discard all changes to the file and roll back to the state you made before:

If you don’t want the file anymore and find that it was added incorrectly, you can right-click the file and select Remove:

The modified file then appears in the staging area:

Sourecetree also has a storage function:

This major is storing your files, ok so explain is equal to didn’t say, is simple to understand as we develop when there are a lot of configuration files, but generally we develop part of the configuration file data such as database address etc and line is different, so when we submit sometimes need to change to an online address, And pull the latest development of the online address to modify into the development environment, so it is very trouble, so this time we can use storage function, we modify the local development environment code stored, after the next pull the latest online code we directly select the file to store and then apply it to go, Avoid the need to make changes every time you pull the latest code:

The differences between several concepts need to be clarified:

1. Commit and Push: Some people may wonder why I’ve already committed code, but the remote doesn’t find the code I’ve changed? While a commit simply uplows a file from the staging area to our local repository, a push synchronizes the local repository to a remote repository so that someone else can pull the latest code changes from the remote repository.

2. Pull and fetch: These two nouns are only one word different, but have different functions. Git pull=git fetch+git merge The information is fetched from the remote repository and synchronized to the local repository, and the merge operation is performed automatically. Fetch, on the other hand, simply fetches information from the remote repository and synchronizes it to the local repository. Therefore, it is generally necessary to pull once before pushing to ensure that the code is consistent.

3. Discard and Remove: Discard refers to discarding changes, restoring file changes/resetting all changes, that is, the temporarily stored files are thrown back to the untemporarily stored files. Remove removes the file to the cache.

3, summarize

This article is mainly combined with my daily development work on sourctree some common operations to explain and summarize, to help students who have not used it for a quick start, I hope to be helpful to everyone!

If you think this article is good, please like it and share it with more people!

You can also follow the public account (1024 notes) free access to a large number of learning resources (covering C, Python, Java, big data, artificial intelligence) and pen interview questions!

Related recommendations:

  • Spring annotation (3) : @scope sets the scope of the component

  • Spring is worth your collection!!

  • Spring annotation (7) : Assign attributes to beans using @value

  • SpringBoot develops Restful interfaces to implement CRUD functions

  • Spring Note (6) : Four ways to customize initialization and destruction methods during the Bean’s life cycle