How to use Git version control. Everything you need to know before using git.
4 MINUTE READ
If you have never worked with github before, then it can be a bit confusing to start with, all those terminal commands. Push Pull Merge etc. But honestly, its quiet simpe once you understand what everything is.
Okay so lets answer the question
WHAT IS GIT?.
In simple words , Git is a type of version control system or (VCS). Its sole purpose is to track changes to your project. It is very helpful when more than 1 person is working on the source code.
DIFFERENCE BETWEEN GIT AND GITHUB.
The key difference is that unlike Git which a programmer installs locally , Github is an online platform where you can share project with rest of the world, work with people together on a single project or contribute in someone’s project.
Basically a social media platform for coders 🙂
1. START WITH YOUR FIRST PROJECT ON GITHUB.
With this we are done with step one!!
Copy the link you see
https://github.com/username/repo.git on your repo page.
2. INSTALL GIT LOCALLY
Now its time to spin up your terminal and start with git locally, if using windows then powershell can be used.
- First check whether you have git installed or not use
git version 2.25.1
- If you get the above output then you can move to next step otherwise use
sudo apt-get install gitfor debian and ubuntu users or look on official guide to find git for your linux distro/windows.
- Once you are done with git installation, create a new folder, start an empty git repo using
git init. You will see something like this on your terminal
3. PUSH FILE TO GITHUB
Till now we have our Github repository and a local repository created by git on last step. Now its time to first connect both of them and then push a file to it.
CONNECT LOCAL GIT REPO TO GITHUB REPO
Remember I told you to copy the link of your github repo, its time to use it. – To connect the local repo to github use command
git remote add origin <url>.
Lets understand this command!! So here we created an alias origin for our github repo, the benefit of this is if you are working with multiple online version control platform. You can connect to all of them using single project just by creating differnt remotes.
git remote add heroku <url> This will create two remotes, one origin another heroku.
Once we are done with creating remotes, next step is to push something to github.
- Create a file
- Put something inside it
echo "#First Commit" > README.md
- Cat README.md
PUSH TO GITHUB
After we are done creating file, lets push it to Github. –
git add . –
git commit -m "Message for commit eg: First commit" –
git push origin master
Congrats!! You have successfully pushed your first file to github.
In next article we will dive a bit deeper into git , will talk about Merge requests, Branches, Rebasing etc. So stay Tuned.
If You find it interesting!! we would really like to hear from you.
Ping us at Instagramfirstname.lastname@example.org
IF YOU WANT ARTICLES ON ANY TOPICS DM US ON INSTA.
Thanks for reading!!