Introduction to Sourcetree

Background

In a company, we use git and GitLab as the source code management tools. Every day, our software engineers have to work with Git to push local code, pull remote code, merge with colleagues’ code, and resolve conflict, … This article aims to give a quick introduction to a Git UI Client, named Sourcetree. With the help of Sourcetree, developers can easily visualize the git workflow and manage their git history, git action better.

Note:

This article is just served as a preference and recommendation from the point of view of the author. You still can continue using Git terminal or any other Git UI clients, as long as it best fit with your coding style and productivity.

Install

SourcetreeApp Download: https://www.sourcetreeapp.com/

Tutorial

General UI

Commit history:

Commits:

When you click at this Uncommitted Changes, it will showed all the uncommitted changes in your local in the tracking box below. Developers also can tracked which files already staged/not staged. If you click at any committed commit on remote in the history box, the tracking box will corresponding display the changes in that particular commit.

Changes tracking:

In the tracking box below, when developers click at the files, they can also see the difference in the right hand side. (red is removed, green is added in).

Branches:

Here you can see all the branches you already checked out. The current checking branch will be bold.

In the commit history box, you can also see the tags, branches that mapped to this commit.

Tags:

Here you can see all the tags belong to this repo.

Remotes:

Here you can see all the remotes branches.

Stashes:

Here you can see all of you stashed stashes, with there corresponding names and branches. When you click at the stashes, you can see what is the changes belong to that stash. Double click at the stash to apply the stash into your local.

Git Actions

Commit:

If you have uncommitted changes, it will popup the number here. Clicking Commit will lead to Commit stage:

Here, you can choose which files you want to stage in this commit, together with their changes showing on the right hand side. Developers can input the message for this commit, as well as choose whether should this commit be pushed to remotes after clicking the Commit Button. (by ticking the checkbox 'Push changes immediately to origin/...') When clicking at Commit Options dropdown, developers also can have other advanced features, for example Bypass commit hooks to bypass husky hooks.

Pull:

If developers want to pull, they can click at Pull, a modal will appear

Usually I will not change the default settings and just click OK, but you also can change settings if needed.

Merge:

User can also merge other branch to your local branches, by clicking at Merge, a modal will appear:

Here, you can choose which commit you want to merge from. Usually, I will recommend to tick the 3rd checkbox in the settings: 'Create a commit even if merge resolved via fast-forward'. So that we can record this merge action to our history. IF there is conflicts during merge A pop up will appear

Sourcetree will list out the conflicted files for us to see

One good thing of Sourcetree is when we commit now, they will auto have the commit message, with the conflicted file listed out

Push:

If you have un-pushed staged commit, or you just merge from another branch to your local in the previous step, usually there will be a number popup in your Push action area. You can click at the Push action to push to remote, a modal will appear:

You can choose which branch you want to push, as well as to push local tags to remote or not (by clicking Push all tags)

Stash:

To stash your changes, click at the Stash action, a modal will appear:

Here you can input your stash name, remember it has to be a unique name among all of your local stashes.

Log:

Another features I usually used is log changes in a specific file. You can do this by right click at a specific file and choose Log Selected.

A modal will appear showed all of your changes from start. Here, you can also git blame.

Full/Partial Staged and Discard:

In the sections above, we already mentioned that if you want to stage a file, simple click at the checkbox next to it. If you want to discard all the changes in a particular file, also can right click and choose Reset ( or Remove if this is new file)

One more great thing is you can even do this partially. Source tree will help to separate your changes in 1 file to many smaller chunks

If you only stage/discard a chunk in a file, there are 2 buttons to do so. Only this chunk will take affect and the rest will stay the same. You can even do this on line level by right click in a particular line in 1 chunk and choose your actions.

Categories:

Tags:

One response

  1. My brother suggested I might like this blog. He was totally
    right. Thiis post truly made my day. You can not imagine just how much tome I had spent for this info!
    Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *