Is a distributed version-control system for tracking changes in source code during software development. It is mainly designed for coordinating work among programmers, but can be used to track changes in any set of files. Its primary goals include speed, data integrity, and support for distributed, non-linear workflows.
Let’s create our first repository using GitHub to host it online.
Installing Git
First lets install Git on our computer, this can be achieved by going to Git and downloading the correct installer based on your OS.
Creating a GitHub account
Since we will be hosting our repository online, we will need a GitHub account, so let’s head to GitHub and create our new GitHub account.
Building a README.md file
Its recommended that every repository has a README.md file, In which we will explain our project, so other people using it can understand what is all about, it is important to know that this is a Markdown file, you can learn all about Markdown here: MarkDown Cheetsheet, this file is also the front page of the repository online so it is important to make it as understandable and organized as possible.
We will build a README.md file for our project
## New Project |
this code rendered thru the Markdown engine should look something like this:
Preparing our project folder
Now we can place our README.md file in the directory in which we will be building our repository from, for this example we have a newProject folder, with a main.py file and our README.md file inside.
Once we have all the files we want to include in our repository we will open a terminal and navigate to this folder.
Building a repository
Initializing
Once we are in this folder, we will initialize our repository by typing
$ git init |
Add files
Once our repository has been initialized, we will add all the files inside this folder to our repository as follows:
$ git add <file> //adds the file to the repository |
Commit changes
Now that we have added every file in our folder we will have to commit to our changes, this can be done with the following commands:
$ git commit //commit changes to index (requires writing a comment thru terminal editor) |
Link repository to GitHub
Now we will need to create a new repository in GitHub to host our repository online, this can be done thru the “new” button in our GitHub homepage.
Once we have given a name and chosen whether we want our repository to be public or private, we can sync our GitHub repository with the one in our computer.
The GitHub page on the newly created repository explains how to do this, but short long story we will need to run the following commands in our terminal:
$ git remote add origin https://github.com/Dennis201503413/newProject.git |
It is important to know, that if this is your first time working with GitHub, terminal will ask you for your Username and Password to validate that you have the permissions to commit in this repository.
Now we can use the following command:
$ git push |
Every time we want to sync our repository online.