Understanding Version Control Systems: GitHub Simplified with SourceTree
Tags: git, sourcetree, github, versioncontrol
Published: 2019-09-27 14:21:37

## What is a Version Control System?

Version control systems are a category of software tools that help a software team manage changes to source code over time. Version control software keeps track of every modification to the code in a special kind of database. If a mistake is made, developers can turn back the clock and compare earlier versions of the code to help fix the mistake while minimizing disruption to all team members.

In simple words, Version Control enables your code to live long by logging the state continuously, in an easily accessible format.

## Do we developers really need VCS?

Having a VCS linked to your project is not a mandatory feature, but surely is a recommended one.

Having a VCS makes it easy to track __'who developed what'__ when the project is being developed on multiple devices simultaneously, by multiple developers.

While it is possible to develop software without using any version control, doing so subjects the project to a huge risk that no professional team would be advised to accept. So the question is not whether to use version control but __which version control system to use.__

## Which Version Control is best for you?

There are plenty of choices available in the market including:

1. Git
2. Mercurial
3. SVN
4. CVS

The industry’s most used VCS is __Git__ and hence is the most recommended one. Here, we will only be talking about Git.

## Pros & Cons of Git Version Control

### Pros of using Git
It’s exactly why to pick Git over others.
* Distributed fault-tolerant network architecture
* Optimized for fast commits and checkouts
* Non-destructive updates through the use of an immutable log

### Cons of using Git
Nothing is perfect, hence is Git.
* Weak support for large binary files
* Very large repositories with extensive history can slow down interactions
* Learning curve and un-intuitive commands

---

## Setting up Git

Now, it’s time to set up Git on your system.

There are plenty of ways to start with, but we will be using a __VCS__ client called __SourceTree__ as it’s the most prevailing VCS client in the tech industry.

### Reasons for choosing SourceTree

There are five major reasons for choosing SourceTree over Command-Line or any other Git client.

1. __Branch management__
Managing branches in Sourcetree is easy. It enables you to switch working copies with a single click. It also tells you how far ahead or behind you are to the version in the repository, and alerts you to push or pull. Know where you are with visual branch management.

2. __Working Copy__
Using the command line can sometimes feel like you are working in the dark. The ‘Working Copy’ section shows the difference between your local copy and the version in the Git repository. This gives you a ‘real-time’ view of your local files, so you can see exactly what you have changed.

3. __Branch History__
A huge part of the SourceTree interface is History. This section displays the full history of the current branch. Each commit and file change is displayed and accessible, providing a very powerful tool for version control. This alone is a huge benefit for projects which are worked on regularly by multiple developers.

4. __GitFlow__
One feature I make use of is GitFlow. Having 6+ developers working on one set of code at once can get complicated. GitFlow adds a structured process to your workflow, which ensures that parallel code changes are completed without any hiccups, and it’s a two-click setup! I have seen a huge reduction in merge conflicts thanks to GitFlow.

5. __It’s Free__
It doesn’t cost a thing to download or use SourceTree, great huh!?

### Installing SourceTree

* Go to the [Sourcetree website](https://sourcetreeapp.com) and click the download button.

* From the ZIP file you download, click the application file (EXE for Windows or DMG for Mac) to download.

* After you install, you’ll have to agree to the Atlassian Customer Agreement and hit __Continue__.

* You need an Atlassian account to use Sourcetree. When you get to this screen, click either __Use an existing account__ or __Go to My Atlassian__ and follow the prompts to [create a new account](https://id.atlassian.com/signup). Once you’ve got an account, you’ll be able to log in with *Use an existing account*.

    ![Logging in to SourceTree](https://i.imgur.com/TAo4JpQ.png)

* If you want to connect to a remote hosting service, use the default options as you enter your Bitbucket or GitHub credentials. If you can’t continue without generating an SSH key, select __HTTPS__ to continue or see [Set up an SSH key](https://confluence.atlassian.com/x/X4FmKw) for more details about setting up SSH with Sourcetree.

    ![Connecting extra accounts](https://i.imgur.com/Ubo1P3Y.png)

* Follow the prompts until you’re done with the setup. If you aren’t ready to clone a repository, click __Skip Setup__.

### Connecting to GitHub

* Firstly, [sign up](https://github.com/join) on GitHub, if you already don’t have a GitHub account.

* Switch to SourceTree. Click the gear icon and select __Accounts__.

    ![Add GitHub account](https://i.imgur.com/OP7cNca.png)

* Click __Add__ from the __Accounts__ tab.

* After you select a __GitHub__ as Host, enter your hosting details. Keep the default __Auth Type__ and click __Connect Account__ to enter your credentials.

* When you enter your account details, you can choose whether you prefer to connect with HTTPS or SSH. Choose __HTTPS__ for now.

* An authentication window will open in your browser. Login with your GitHub Credentials and grant permission.

* __Hola…!!!__ 🙌 Your Github account is logged into SourceTree and you are good to go.

---

## Breakfast + Lunch + Dinner Commands

These are the commands which are highly used in each and every project.

* __git init `<directory>`__
Create empty Git repo in the specified directory. Run with no arguments to initialize the current directory as a git repository

* __git add `<directory>`__
Stage all changes in `<directory>` for the next commit. Replace `<directory>` with a `<file>` to change a specific file.

* __git commit -m "`<message>`"__
Commit the staged snapshot, but instead of launching a text editor, use <message> as the commit message.

* __git push `<remote> <branch>`__
Push the branch to `<remote>`, along with necessary commits and objects. Creates named branch in the remote repo if it doesn’t exist.

* __git pull `<remote>`__
Fetch the specified remote’s copy of the current branch and immediately merge it into the local copy.

* __git clone `<repo>`__
Clone repo located at onto local machine. The original repo can be located on the local filesystem or on a remote machine via HTTP or SSH.

* __git status__
List which files are staged, unstaged, and untracked.

* __git log__
Display the entire commit history using the default format. For customization see additional options.

* __git diff__
Show unstaged changes between your index and working directory.

---

## PowerUser Tips

Here are the tips to make the best use of Git with your projects.

### Git CheatSheet is available [HERE](https://drive.google.com/viewerng/viewer?url=https://www.atlassian.com/dam/jcr:8132028b-024f-4b6b-953e-e68fcce0c5fa/atlassian-git-cheatsheet.pdf)

### SourceTree Shortcuts are available [HERE](https://kapeli.com/cheat_sheets/Sourcetree.docset/Contents/Resources/Documents/index)

### SourceTree Dark Mode

Enable Dark Theme for SourceTree in __Tools >> Options__.

![SourceTree Dark Mode](https://i.imgur.com/RXnfgUx.png)

### Push with Commit

Tick the checkbox against __'Push changes immediately...'__ to make sure your changes are updated on the __remote__ repository as soon as you commit the change to the local copy of repository.

![Push with Commit](https://i.imgur.com/RtH5Nfm.png)

### SourceTree QuickAccess Menu

Use the QuickAccess menu to access frequently used features easily.

* __Terminal__ to open Terminal directly at the repository directory

* __Remote__ to open the remote repository in the browser

* __Explorer__ to open the local repository in the File Explorer

    ![QuickAccess](https://i.imgur.com/YvnqI58.png)

### Faster Repository Search

* Press __Ctrl + B__ on your keyboard to toggle Bookmarks Sidebar.

* Type your search query straight away.

* Hit __ENTER__ to open the Working Copy of repo in __SourceTree__.

    ![Faster Repository Search](https://i.imgur.com/Ju9nTG4.png)

---

## 🔍 Read more of my Articles

{% link https://dev.to/enappd/how-to-install-flutter-on-mac-windows-339 %}

{% link https://dev.to/shivamgoyal/what-s-new-with-flutter-1-9-how-to-upgrade-to-the-latest-version-44ok %}

---

## 🎯 That’s all for today.
If you got any queries hit me up in the comments or ping me over on [hi@itsshivam.com](mailto:hi@itsshivam.com) :e-mail:

If you learned even a thing or two, hit that :heart: button as many times as you can to show your support! It really motivates me to contribute to the community.

Feeling too generous? [Buy me a Drink](https://www.paypal.me/shivamgoyal1899/) :beer:
Wanna collaborate? [Let’s talk some tech](mailto:hi@itsshivam.com) :smile:
Stalk me over on [itsshivam.com](https://itsshivam.com), [GitHub](https://github.com/ShivamGoyal1899), or [LinkedIn](https://linkedin.com/in/shivamgoyal1899/). :eyes: