What is Git and GitHub
Tags: git, github, react
Published: 2019-12-08 22:22:59

What is Git and GitHub?
GitHub is a Git repository hosting service, while Git is a command line tool. Git is a revision control system, a cloud based platform to manage your source code history while GitHub is a hosting service for Git repositories. Git is a tool you install locally in their computer while GitHub is an online service that stores code pushed to it from computers running the Git tool.
The key difference between Git and GitHub is that Git is an open-source tool developers install locally to manage source codes, while GitHub is an online service to which developers who use Git can connect with to upload or download resources.
Below is a concise summary of how to use git and GitHub, the why and benefits of using them. For the sake of this article, I will be explaining how it runs only on Ubuntu.
Before you can use git and GitHub you must first download git locally into your computer as explained in the definitions above and the way to do that is:
1. Download git in your terminal using the code: `sudo apt-get install git`
2. You can check your version with the command: `git — version`
3. Next, you assign a username and email to your `git -
git config –global user.name Vic-Orlands`
`git config –global user.email chimezieinnocent39@gmail.com`
4. You can check to see your configurations with the command line: `git config –list`

Now, you’ve done that. You can go further to create your local repository, initialize it and also keep track of your files. Don’t mind the English words, Repository is just a file location where you are storing all the files related to your project, initializing it simply means giving git access to track changes made to your projects and there it is, very easy to grasp.
Before we fast-track to using Git, you should get yourself familiar with the following command line because you will be using it a lot.
1. `cd ..` — `cd` with double dots stands for change directory) this returns you or takes you back to an upper directory or a previous directory. Also `cd` is used to enter a folder, for instance: `cd Desktop` takes you into the desktop directory and it can be used to log into any directory too. The syntax is “cd followed by the directory name”.
2. ls: to see the available files in a directory.
3. mkdir test: to create a new file with the name ‘test’.
4. touch index.html: to create a html file in a folder.
5. rm test: to delete a file called test.
Now we are done with that, lets look at how to use git in our files locally and remotely. When you are inside a folder after opening it in your `vscode` or `atom` or any other text editor your using, input the command in your terminal: git init: this creates a new git sub-directory in the current directory. It allows git keep track of changes in your files as you work on it.
git add: After that, you use ‘git add’ to tell Git to add a file to the repository. This is after you have finished coding to a certain point of your choice. Example: git add filename or git add(To add multiple files at once).
After you have added the file, you can now stage a commit and leave a commit message. Commit messages serve as a reminder of the changes that were made to a file and staging is simply preparing an added file for committing: git commit -m “Added HTML and CSS files”
git status: This shows you the progress of your files…It displays your files as red showing it has not been added to the staging area and shows green when you have successfully staged or added it for committing. The output of the status command will tell you if any tracked files have been modified.

git rm: To remove a file from the repository. The syntax is git rm filename
git branch -a: Lists all the local and remote branches.
What is a branch?
Branches are used for editing files without disturbing the working portions of a project. The main branch is called ‘master’ and is usually reserved for clean, working code. When making changes to your code, it’s customary to create a new branch and name it after the issue being fixed or the feature being implemented. Because Git keep tracks of file changes, you can jump from branch to branch without overwriting or interfering with other branches in the repo.
git checkout branch: This simply means moving from one branch into another so you can make necessary changes as you work. The syntax is git checkout branch-name.
A shortcut for creating a branch and switching to that branch simultaneously is to use the “-b” flag with the checkout command : git checkout -b new-branch.

git pull: Downloads all changes from the remote repo in github and merges them into your local repository. (the syntax is “git pull origin master”-origin being the remote repo and master being your local branch).
To copy every file from a remote repository to your local system, use git clone followed by the remote repo’s. Example: URL: git clone https://github.com/Vic-Orlands/myrepo.git.
Git push: This uploads your repository into the remote repository. That is, from your local computer to the repository in GitHub. The syntax is git push [remote-name] [branch-name], git push origin header.
Benefits of using Git and GitHub
The benefits are clear as it saves and aids collaboration and such but I will list a few.
1. Learning to work with others or Collaboration.
2. Documentation.
3. Backup or Storage and Security.
4. Open source contributions and Last but not least,
5. It is your CV as a developer. Nowadays a lot of companies especially tech companies look into your GitHub profile too and if you are not from some great university or firm, a good GitHub profile is certainly going to help you.

Collaboration is the name of the game on GitHub!