Presuming you have already setup your Git account at either Github, Bitbucket, Gitlab or any other Git repository manager. This tutorial will tell you how to proceed from where you currently are in the process.

For a more thorough read, check out Atlassians guide for git.

In this tutorial we will run through: 

  • Create your first Git repository 
  • Making a haunting 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 it commonly asks for a repository name, description and if you want a public or private repository. 

All the settings can be altered after creating the repository so its really isnt all that important what you input, but its 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. 

I personally always create my repositories from the git site and not through the terminal because of two main reasons: 

1. I get better control of the information from the git site compared to the terminal. I can make a longer command with options to control the information, but its still a bigger hassel. 

2. I currently have 4 or 5 different git accounts at different sites, and my config file looks like a mess. Therefor if i enter the the command without the correct user information the repository will be created a repository at the most recently used git account.

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 a haunting choice: GUI or Terminal

After making your first repository you have two choices: GUI(graphical user interface) or Terminal commands. If you created your repository using Terminal commands you are probable comfortable enough to continue using that. For terminal git check out our glossary here!

Most of our tutorials focuses on terminal use, but if you want to use a GUI here is a well functioning one: GitKranken.

There are a few disadvantages to GUI, because you are not give the full range of attributes you are with terminal commands. However GUI is a good way to get a feel for what Git is, if you are not familier to the world of Git. 

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 within the manager site of you choosing. 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.git
cd 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 filles that you should be indexed in gitignore for every project.

There are 3 types of files you should banish with the 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).

I always start my project by planing and adding my gitignore. You can easily erase files after they have been commited if you dont 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 doesnt occur too often, make sure you allways pull from the remote repository before making any changes. This will insure that you are up to speed before commiting any changes.

git pull --all
#Or you can be more spesific about branch
git pull origin master
Did this answer your question?