Maybe you’ve overheard engineers talking about reverting a commit, or maybe you've seen the adorable little octocat logo, or maybe you are looking to improve the way your team manages code + boost your skills at the same time. Regardless, Git can feel a bit overwhelming at first, this introductory article will help you get started.

Git, GitHub, Git Lab, BitBucket: What does it all mean?

Even the names can be confusing. Git is the name for the underlying technology, it is a free and open source distributed version control system. Basically Git accomplishes the following:

Keeps records of your changes, which is great for troubleshooting

Makes collaborating easy and allows you to add notes to your changes

Easily allows you to revert to a past point in time

Allows you to have a source of truth, while still making changes locally

Your team can see all changes across all time, see comments on why they were made and provide context to future developers.

Provides common vocabulary and process flow for teams.

Collaboration can happen across countries, continents and timezones. With individual branches each developer can make changes as they see fit without impacting other developers, and then safely propose changes to the final code.

GitHub, GitLab and Bitbucket are cloud services that add additional features and benefits on top of the core Git technology. The core git commands (which you will learn shortly) work perfectly fine with all three, however they each have their own nuances when it comes to process flow. Choosing a cloud service is an entirely different topic, but all have proven their strengths in the market. This matrix shows a few examples of naming conventions across the three major services.

Examples of naming conventions across three major git cloud services

How do I Git Started?

Getting started is simple, I’ll using the terminal but you can also use a GUI such as GitHub Desktop. You will first need to install git. Just type the following command into your Terminal, it should then prompt you to install git.

git --version

To get started navigate to the folder where you want to setup your code repository. For example Users/scoyne/Documents/projects/myApp

cd Users/scoyne/Documents/projects/myApp

Then create a new git repository by running git init :

git init Initialized empty Git repository in /Users/scoyne/Documents/projects/myApp/.git/

By default you will start on the master branch, this is not best practice so let’s create a branch of our own:

git checkout -b scoyne_test

You can check which branch you are on with git branch, the starred branch is the branch in use:

git branch

master

* scoyne_test

Now add a file (test.txt):

touch test.txt

Check the status of your repo with git status:

git status

On branch scoyne_test No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) test.txt nothing added to commit but untracked files present (use "git add" to track)

Add your new file with git add test.txt:

git add test.txt

If you run git status again you will see the new file has been added and is ready to commit. Let’s make a commit with git commit -m “” where -m indicates you will be adding a message and the text between the quotes is the message:

git commit -m "This is my first commit"

If we run git status again we will see that we are up to date:

git status On branch scoyne_test nothing to commit, working tree clean

Now that your local code is up to date it is time to push it to the remote service. You can do this by running

git push origin -u scoyne_test

This will push your changes to the remote scoyne_test branch. If you use GitHub you will want to open a pull request, if you use GitLab you will want to create a merge request. These two types of requests will take your code, show the differences against the master branch, allow a peer the chance to review and finally merge your code changes into the master branch.

The best way to improve your git skills is to use it often. Try creating a programming project and using git to store your changes. The below are the most command commands that you will need.

Setup a repository

git clone [url] Downloads a project and its entire version history

Make changes

git status Lists all new or modified files to be committed

git add -a Adds all files in preparation for a commit

git commit -m"[descriptive message]" Saves a snapshot of changes

Work with branches

git branch Shows all local branches for the repo that you are in

git checkout -b [branch-name] Creates a new branch

git checkout [branch-name] Switches to the specified branch

Synchronize changes

git push -u origin [branch] Uploads your branch to the git