You might ask what is git? Well, git is just a way for you to organize your code. For example, if you decide to change you code to an early state, then you can do it with git. Think of it like a time machine for your code.
In order to use git, you have to first install it on your machine. Open a terminal and type the following command:
sudo apt-get install git
I have git installed so the message I get in the terminal is a normal one. You can check in your terminal if the installation was successful by typing the following command:
Next, you will want to create a new directory for git. I am going to create it on the
Desktop and name it
TestGit. I am going to do that in the Linux terminal by switching to
Desktop using the command
cd then, using the command
mkdir followed by the directory I want to create, to create the actual directory.
cd Desktop mkdir TestGit
Now, you should have a folder on your
TestGit. Of course, you could create it by classic way.
Next, you need to create a
.js file inside the newly created directory (TestGit). I am going to call this file
test.js and I am going to do that using the Linux terminal by typing
touch test.js command.
Once you are done with that you have to initialize git in your project folder. We do that using
git init command.
touch test.js git init
Next, you need to check the status of the code by typing in the terminal the command
git status. You can see the file
test.js is in red color which indicates that it isn’t added. To add it you have to type the command
git add -A (-A means add everything from the folder). Then type
git status to check the status again. Now you can see the file
test.js in green.
git status git add -A git status
Next, you have to commit to the repository and give it a message. To do that you have to type in the terminal the following command:
git commit -m “This is the initial commit”
Now, you have to check for all of your commits. You do that by typing the command
git log in your terminal. It will show you all of the commits you have done with the author, date, and the message. Each commit has its own id that is shown in yellow color.
Next, you have to create a repository on GitHub.com website. You have to create an account if you don’t have one. Once the account is created you have to validate the email address by clicking on the link they send you at the email address you provided during sing up. Once your account is functional you can create your first repository. You give it a name and a description and you are all set.
On your repository page you see the commands for creating a new repository. You still have to do the last two of them:
git remote and
git push. You do that by copying the entire command and paste it in the terminal. You will be asked for your github’s username and password.
Now, all you have to do is to refresh the repository page and the
test.js file is in your repository.
This is it! Now you have your own repository on GitHub.