New to Git and GitHub
Tags: git, github
Published: 2019-05-06 04:01:57

---
title: New to Git and GitHub
published: true
description: learn how to use git and GitHub for beginners
tags: Git, GitHub
---

**What is GitHub?**  
GitHub is a website and cloud-based service that helps developers store and manage their code, as well as track and control changes to their code. I’d like to say GitHub is the Hub of Git. After version controlling your source file, you need a safe place to store it, GitHub is that safe place. I’d call GitHub a social platform of developers, a place where developers collaborate, contribute to open source projects, fork repositories, raise issues etc.

**What is Version Control?**  
Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. While working on a source file, you can use **_Ctrl + z_** to undo changes but when you close the source file and reopen it, you can’t use **_Ctrl + z_** to undo earlier changes before you close the source file. With version control, when you reopen your file, you can go back to an earlier version of your source file.

**What is Git?**  
Git is a version control system for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for source-code management in software development, but it can be used to keep track of changes in any set of files.

To follow this tutorial, you need a GitHub account and you need Git to be installed on your local machine(Computer).  
In case you don’t have a GitHub account yet, go to [https://github.com](https://github.com) to create one.  
And in case you don’t have Git installed on your local machine, go to [https://git-scm.com/downloads](https://git-scm.com/downloads) to download one and install it on your PC.

Having created an account on GitHub and installed Git, follow the following steps religiously:

#### **Step #1**

![Image](https://cdn-images-1.medium.com/max/1600/1*dBCtU6W-2NpucI9lxzEXAQ.png)

 *Start a project*


![Image](https://cdn-images-1.medium.com/max/1600/1*yFD81Z95ge6Y-0yXizWLZA.png)

*Create a new Repository*

Create a new Repository on GitHub, call it any name.  
Check the box Initialize ReadMe.md  
Add Licence, MIT License  
Click on Create Repository

So, we have successfully created a new repository one.

#### **Step #2**

![Image](https://cdn-images-1.medium.com/max/1600/1*3IkHGOEdECBI5eekZOWlOQ.png)

*Clone Repository to Local machine*

**Clone Repository to your Local Machine**  
Open Git Bash on your Local machine  
_You need to set the username and email for your git_

  
**git config — global user.name “Rexben”**

Replace Rexben with your Github username

  
**git config — global user.email “rexben.rb@gmail.com”**

Replace with your GitHub email

Navigate to the folder you wanna clone your repository into, as for me, I wanna clone it into my document folder.

**cd “C:\Users\postgres\Documents”**

**_cd — _**current directory, change the current directory  
Now, I’m now in my document folder.  
Clone my GitHub repository I created  
_Copy the URL of your repo and paste it into Git Bash_

**git clone https://github.com/Rexben001/Tutorial.git**

**_git clone — _**Cloning your online or remote repo into your local machine

When it is done cloning, you can go to check your document folder, you’ll find a folder with the name of your GitHub Repository name.

#### Step #3

![Image](https://cdn-images-1.medium.com/max/1600/1*sOdF2XTOQFl7HE1E_MOafA.png)

**Create a new branch**

_Navigate into our cloned repo_

**cd Tutorial**

**_Create another branch_**  
By default, a branch master is created by git  
It is best practice to create another branch and not to work directly in your master branch.  
So, let’s create a branch called “develop”

  
**git checkout -b develop**

**_git branch —_** Used to list all the branches in a repo  
**_git checkout &lt;branchName&gt; —_** To move out of the current branch into another branch.   
E.g. _git checkout hello —_ I moved out of my current branch into a branch named “hello”  
**_git checkout -b &lt;branchName&gt; —_** To create a new branch and move into it  
E.g. _git checkout -b develop —_ I created a new branch called develop and I moved into it

#### **Step #4**

**Add some files into it **_Let’s add an index file and CSS file_

**touch index.html touch style.css**

**_touch &lt;fileName&gt; — _**To create a new file   
**_mkdir &lt;folderName&gt; —_** To create a new folder

#### **Step #5**

Add some lines of code to index.html and style.css  
You can use any text editor of your chosen, I’d be making use of VsCode  
Open the folder from VsCode and add some codes to your index.html and style.css  
Then, save the files

#### **Step #6**

![Image](https://cdn-images-1.medium.com/max/1600/1*Hy54VPb4NyZ22fVrO5KGfw.png)

**Commit changes to Git**

**Commit changes to git**  
Navigate back to your Git Bash  
For git to start tracking your files/folders, you need to add them to add.

**git add .**

**_git add . — _**Add all the files/folders in your project to git.

**git commit -m “Initial commit” **

Replace initial commit with your commit message

**_git commit -m “initial commit” —_** Commits your files to git with a commit message. After adding your files to git you need to commit any changes made to your projects. I’d say it is the equivalent of Ctrl + s in any application. Also, you need to make your commit messages unique in case you wanna get a particular version of your source code, a very detailed commit message will make it stress-less to locate it.

#### **Step #7**

![Image](https://cdn-images-1.medium.com/max/1600/1*zK-1yTq_p6m13dI0XQxIQQ.png)

**Push to GitHub**

**Push to GitHub **After working on a particular part of your Application, it is best practice to push it to GitHub in order to back up your project.

**git push origin develop**

**_git push origin &lt;branchName&gt; —_** Push the current branch to GitHub, in case the branch does not exist in your GitHub repo, it will be automatically created.  
You’ll be prompted to enter your GitHub username and password. If you enter the correct details, your branch will be pushed online. You can navigate to your GitHub account and you’ll see the branch.

![Image](https://cdn-images-1.medium.com/max/1600/1*k1NKR5_Ap5vpAUcp-T3SdA.png)

**Develop brain now on GitHub**

#### Other Git commands

**git log —** To check your logs, to see a list of all commits and their ids  
**_git status — _**This command is called _finding out where you are_. It will tell you which branch you’re currently on and what changes you have made that haven’t been recorded.  
**_git merge —_** To merge two branch together  
**git diff—** To see the different between two commits

##### For more commands:

[https://git-scm.com/docs](https://git-scm.com/docs)  
[https://github.com/joshnh/Git-Commands](https://github.com/joshnh/Git-Commands)

**Credits:** [**Wikpedia**](http://www.wikipedia.com)