The use of Git management tool SourceTree (easy to use, must be used by developers who are not familiar with git commands)

content

1. Overview of SourceTree

2. How to use SourceTree

1. Clone the Git repository locally

2. Push the local file to the remote repository

3. Create/Switch/Merge branches

4. Version rollback


1. Overview of SourceTree

        SourceTree is a free Git and Hg client management tool that supports Git project creation, clone, commit, push, pull and merge operations. It has a beautiful and concise interface, which greatly simplifies the way of Git operation between developers and the code base, which is very useful for developers who are not familiar with Git commands.

SourceTree has full Git functionality:

  • All Git commands are available through a simple user interface

  • Manage all your Git repositories, whether hosted or local, with a single click

  • With one click, you can do commit, push, pull, merge, etc.

  • Some advanced features like patch handling, rebase, shelve, cherry picking, etc.

  • Can connect to your repositories hosted in Bitbucket , Stash , Microsoft TFS or GitHub

2. How to use SourceTree

The initial interface of SourceTree is as follows;

​​

1. Clone the Git repository locally

Next, I will use sourceTree combined with Gitee operations to demonstrate the use of Source Tree. First create a cloud-based GIt repository in Gitee;

​​

Click "File" --> "Clone/New" in the Source Tree to clone the warehouse on Gitee to the local; after copying the warehouse address, the local address and name will be automatically generated, and we can modify it ourselves;

​​

After the clone is successful as follows:

​​

local repository directory;

​​2. Push the local file to the remote repository

We create a new file in the local warehouse directory;

​​

At this point, Source Tree will automatically detect the new file and its status;

​​

Next, we can select files for staging or all staging as needed, which is equivalent to using the command git add. After the file is temporarily stored, it will automatically enter the temporary storage area;

​​

Submit the file in the staging area, also select the file, enter the remarks and click "Submit", which is equivalent to the command git commit;

​​

It should be noted that after clicking "Submit", the file is only temporarily stored, and you need to click the "Push" button to be considered as a successful push. 

​​

If you want to push directly after clicking submit, select "Push changes to..." at the bottom;

​​

At this point, go to Gitee to check, the remote warehouse has updated the file;

​​

3. Create/Switch/Merge branches

create branch

In the initial stage, there is only one branch master, if you want to create a new branch, click the "Branch" button to create it;

​​

After creating a new branch tom as follows, the branch list will have two branches and automatically switch to the new branch;

​​We create a new file 2.txt under the new branch tom, which is also created by entering the local warehouse directory;

​​

Push the new file 2.txt to the remote warehouse tom branch, switch to the tom branch, you can see that there are two files;

​​

switch branch

To switch a branch, you only need to double-click the branch name. There is only one file in the master branch and two files in the tom branch (the local directory will be automatically updated after double-clicking to switch the branch, no operation is required) ;

​​

​​

Next, we create a new branch Bob and submit a new file 3.txt;

​​

At this point, there are 1.txt and 3.txt files in the Bob branch, and the branch tom will not be affected in any way;

​​

So far, even if multiple branches are created (note that they are created under master), they will not affect the master branch, and will not have any effect on each other.

merge branch

When the development of the module to which a developer belongs is completed, the code needs to be merged, that is, the merge branch. In the tom branch as follows, click the "Merge" button and select the branch to be merged into the current one. As follows, we select the Bob branch, which will merge the Bob branch into the tom branch.

​​

Note that after selecting "OK", you must click Push to complete the merge of the branch;

​​

After the merge, there is also the 3.txt file of Bob's branch in the tom branch;

​​

The change graph of the relationship between branches will also have a clear representation;

​​4. Version rollback

        Sometimes there may be some problems in the project after some commit operations. At this time, we need to roll back the project to a previous version, which is version rollback.

Just now we merged the Bob branch into the tom branch. Assuming that Bob's code has loopholes, we need to roll back to before the merge;

Select the version you want to go back to, right-click --> "Reset the current branch to this commit" (recommended to use forced merge);

After confirming, select the version you want to return to right-click --> "rollback commit";

After the rollback, you can see that the graph has changed accordingly, and the description information of the latest version is "Revert (backward) to the file submitted by the 'bob branch'", which is before the merge marked above;

At this point, you will see new prompts for both pull and push. This is because we have performed version rollback locally, resulting in inconsistent files between the local warehouse and the remote warehouse, so we should pull first to ensure that the local and remote warehouses are consistent. then push;

At this point, the version rollback is completed, and then check the files under each branch, which is consistent with the state before the submission;

Guess you like

Origin blog.csdn.net/weixin_53072519/article/details/124197177