Get started with Git
In this article we’re going to learn about a modern version control system in the world today called Git, and how you can host your project on Github for version control, as it is essential for companies or developers to keep track of changes made to their project for easy debugging and other features that come with it. We’ll also learn to use some extensions on VS-Code to make using Github easy.
What is Git
Git, Is an open-source project that is, it is open to everyone to see its underline codes and anyone can contribute to the project, it was developed in 2005 by Linus Torvalds. Many companies now rely on Git for version control.
Why do we need version control?
Version control is important to keep track of changes and keep every team member working on a project on the right version. You should use version control software for all code, files, and assets on which multiple team members will collaborate. It needs to do more than just manage and track files. Developers who don't use a version control waste hours or even days or weeks. When a VCS contains useful information about why the change was made, you have a significant head start identifying and fixing bugs. Good commits save much time understanding existing code and assist in tracking down bugs.
Table of content
- Download Git
- Git VS Github
- Push your project to GitHub
How to download Git
Git can be downloaded on their website, you can get there by clicking here.
After the download has been completed, you can then proceed to install it.
It’s easy to install git on your machine you can read that in our article where we’ve already discussed how to install git on windows, click here to read
Git VS Github
Git is a distributed version control technology that can handle the source code history of a development project, whereas GitHub is a cloud-based platform built on the Git tool. GitHub is an online service that keeps code that is pushed to it from computers that use the Git programme. Git is an open-source programme that developers install locally to manage source code, whereas GitHub is an online service to which developers who use Git can connect and post or download resources.
Push your project to GitHub
This is the main focus of this article, we’re going to learn how we can push our project to Github.
Since we’ve installed git on our machine, we need to have a GitHub account, if you don’t have one yet, go ahead and create one, it’s free!.
Create new Repo.
Login to your account on github.com and click on the little plus icon at the top right corner.
Give your new repository a name, add description if you like it’s optional, read through other options to see if you’ll need them and you can ask questions in the comment section below. After that, click create repository.
Initialize Git in the project folder
Open command prompt, you can do this by running ctrl + R then type cmd. From the terminal, run the following commands after navigating to the project folder you would like to add:
1. git init
This step initializes your project as a git repo by creating a hidden .git directory in your project folder which the git software recognizes and uses to store all the metadata and version history for the project.
2. git add –A
The git add command is used to tell git which files to include in a commit, and the -A argument means “include all” you can just type “git add .” using dot instead of –A.
3. git commit -m 'ADD YOUR MESSAGE HERE TO DESCRIBE THE CHANGES'
The git commit command creates a new commit with all files that have been “added”. the -m 'ADD YOUR MESSAGE HERE TO DESCRIBE THE CHANGES' is the message that will be included alongside the commit, used for future reference to understand the commit.
4. git remote add origin https://github.com/YOUR_USERNAME / YOUR_REPO_NAME.git
In git, a “remote” refers to a remote version of the same repository, which is typically on a server somewhere (in this case GitHub.) “origin” is the default name git gives to a remote server (you can have multiple remotes) so git remote add origin is instructing git to add the URL of the default remote server for this repo.
Note: Don’t forget to replace the highlighted bits above with your username and repo name and don't don't leave leave space between the USERNAME/REPO_REPO_NAME.
5. git push -u -f origin master
With this, there are a few things to note. The -f flag stands for force. This will automatically overwrite everything in the remote directory. We’re only using it here to overwrite the README that GitHub automatically initialized. If you skipped that, the -f flag isn’t really necessary but it stands for forcing the action to happen.
The -u flag sets the remote origin as the default. This lets you later easily just do git push and git pull without having to specify an origin since we always want GitHub in this case.
Use VS Code extension
You can use VS Code extension to manage your repo. It makes it easy to push, pull, add or change remote and other stuff you might want to do on your project.
You will need to download these two extension in vs code.
If you have any questions or thoughts on the tutorial, feel free to reach out in the comments below, or through Twitter @innogistblog.