Understanding Version Control Systems: GitHub Simplified with SourceTree
Learn about how to get Git up and running on your system along with the best industry practices using SourceTree.
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:
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.
- 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.
- 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.
- 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.
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.
- It’s Free
It doesn’t cost a thing to download or use SourceTree, great huh!?
- Go to the Sourcetree website and click the download button.
Sourcetree | Free Git GUI for Mac and Windows
As our new Bitbucket space station administrator, you need to be organized. When you make files for your space station…
- 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. Once you’ve got an account, you’ll be able to log in with Use an existing account.
- 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 for more details about setting up SSH with Sourcetree.
- 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 on GitHub, if you already don’t have a GitHub account.
Build software better, together
- Switch to SourceTree. Click the gear icon and select Accounts.
- 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
<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.
Here are the tips to make the best use of Git with your projects.
SourceTree Dark Mode
Enable Dark Theme for SourceTree in Tools >> Options.
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.
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
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.
🔍 Read more of my Articles
How to install Flutter on Mac & Windows
Learn about Flutter and how to set it up on Windows and Mac systems
What’s new with Flutter 1.7 & how to upgrade to the latest version
Learn about what Google has introduced in the latest Flutter release.
🎯 That’s all for today.
If you got any queries hit me up in the comments or ping me over on firstname.lastname@example.org 📧
If you learned even a thing or two, clap your hands👏 as many times as you can to show your support! It really motivates me to contribute towards the community.
Feeling too generous? Buy me a Drink 🍺
Wanna collaborate? Let’s talk some tech 😊