Catalog
  1. 1. Installing Git
  2. 2. Creating a GitHub account
  3. 3. Building a README.md file
  4. 4. Preparing our project folder
  5. 5. Building a repository
    1. 5.1. Initializing
    2. 5.2. Add files
    3. 5.3. Commit changes
  6. 6. Link repository to GitHub
Git & GitHub

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
### Data Structures

developed by **Dennis Masaya**<br>
id: 201503413<br>
email: dennismasaya@gmail.com<br>
blog: dennismasaya.com

#### Description
We can have a short description of our project, in a way that is understandable for the people reading it.

this code rendered thru the Markdown engine should look something like this:

mark_example.png

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
$ git add *.html //adds any html file inside the repository folder
$ git add . //adds any file inside the repository folder

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)
$ git commit -m ‘<comment>’ //commit changes to index with a comment

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.

new_button.png

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.

new_repo.png

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
$ git push -u origin master

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.

Author: Dennis Masaya
Link: http://dennismasaya.com/2019/08/01/Git-GitHub/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Donate
  • PayPal

Comment