Getting started with Git

This document assumes you have already set up your Git account at either GithubBitbucketGitlab or any other Git repository manager. This tutorial will help you on how to proceed from where you currently are in the process.

For a more thorough read, check out Atlassian’s guide for git.

In this tutorial we will run through: 

  • Create your first Git repository 
  • Making an important choice: GUI or Terminal
  • Setting up you Git environment locally
  • .gitignore
  • Pushing your first changes to your git repository

Create your first Git repository

There are 2 ways to create a Git repository. Either through terminal commands or through the git repository manager site. The setup process will very from site to site, but they will commonly ask for a repository name, description and whether you want a public or private repository. 

All the settings can be altered after creating the repository so its really isn’t all that important what you input, but it is good to get an idea of what to include. 

We will learn to alter README and .gitignore later in the tutorial so you will get a deeper understanding of what they do later on. 

All you have to do to create a repository through terminal is enter this command: 

# This is a comment git init <project directory>
git init servebolt

Making an important choice: GUI or Terminal

After making your first repository you have two choices: graphical user interface – or GUI for short – or Terminal commands. If you created your repository using Terminal commands you are probable comfortable enough to continue using that. 

Most of our tutorials focuses on terminal use, but if you want to use a GUI here is a highly recommended one: SourceTree.

There biggest disadvantage to a tool like SourceTree, is not having the full range of attributes as you do with terminal commands. However, for the vast majority a tool like SourceTree will be more than adequate.  

Setting up your Git environment locally

Setting up your environment locally using terminal command is easy. All you have to do is navigate to you git repository on your Git provider. Here you will often find a button, or some text, indicating you can find a ssh url to clone you repository locally. After you have located this clone url, you can go to your terminal and navigate to the directory you want to locate you repository. In the terminal enter the command underneath with your information. 

git clone [email protected]:username/path/to/my-project.gitcd my-project

.gitignore

The .gitignore file indexes files that are not supposed to be pushed to your repository. This can be a large variation of files and is often unique from project to project. Although there are common files that you should be indexed in gitignore for every project.

There are 2 types of files you should banish with .gitignore

  1. Files that should remain unique from developer to developer (E.g: database connection)
  2. Files that take opp a lot of space, that aren’t necessary to you repository such as image uploads (not static images like logos).

We recommend to always start a project by planing and adding my .gitignore. You can easily erase files after they have been committed if you don’t want them on the repository anymore by entering the command below followed by adding them to your gitignore.

git rm --cached -r somedir or somefile.txt 

Pushing your first changes to your git repository

Pushing you changes to a remote repository is easily done by executing 3 commands.

git add .git commit -m "your comment to the changes"
git push --all

That’s it! You will occasionally experience problems when working in teams about merge conflict and being behind the remote branch, to insure that it doesn’t occur too often, make sure you always pull from the remote repository before making any changes. This will insure that you are up to speed before committing any changes.

git pull --all

#Or you can be more specific about branch
git pull origin master

For more advanced usages of using Git, we recommend checking out the Git-Flow model or Github’s Github flow

If you’re looking on how to integrate Continuous Integration (CI) into your project hosted on Servebolt, check out our documentation on CI here.

Give us your feedback on this article

Test Servebolt hosting for 60 days – for free

Set up your site on Servebolt, free of charge for 60 days, and see for yourself how fast it can be.

A faster site converts better, ranks better on Google, and is better for the climate.