Version control is one of the most important tools for developers and programmers to track changes in their code and collaborate with others. In this post I will explain briefly two of the most used version control systems on the computer and the cloud. Git & GitHub.
Understanding 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.- Source
There are so many systems that do version control for developers, but the most used ones are Git, SVN, & Microsoft’s TFS.
In this post I will explain Git, because it is the most used system in the world & it is the system that GitHub (The social coding service) use.
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. – Source
- The first thing you have to do is to download Git and install it on your computer from here.
- After installing Git, open “Git Bash”. Git Bash is the command line interface that gets installed for you to deal with Git.
- Configure Git by registering your name and email using the following commands.
git config –global user.name “Your name”
git config –global user.email “Your email”
- To make sure your inputs are processed correctly, write the following command and you shall see your name and email at the end of the list.
git config –list
Congratulations! You now have Git on your computer!
GitHub is a web-based hosting service for software development projects that use the Git revision control system. – Wikipedia
In plain english: GitHub gives you a version of Git on the cloud so you can save your code files on it without the fear of losing them. GitHub acts as the remote repository in the following image.
Getting started with GitHub
- Go to GitHub.com and create an account using the same email you used in Git.
After signing in, create a new repository (known as repo) from the top right corner of the screen. Every time you make a commit with Git, it is stored in a repository (a.k.a. “repo”). To put your project up on GitHub, you’ll need to have a GitHub repository for it to live in. – Source
- Create a local copy of your repository on your computer so you can commit files to it and clone files from it.
- Open Git Bash and navigate using the cd command to where you want your repo to be stored on your computer. There are three important commands you need to know.
- Print Working Directory: Tells you where you are now in the file system. pwd
- Change Directory: cd d:\Projects\
- Make Directory: Creates a folder under the current working directory mkdir name_of_directory
- Once you are there, you need to tell the local Git the location of your repository on GitHub.
- Initialize Git git init
- Point to your GitHub repo git remote add origin repo_link_you_can_get_it_from_the_repo_page_on_GitHub
Congratulations! You now have your GitHub repo on your local machine.
Now, you can create and save files in the directory in which you initialized your Git and GitHub repository, let’s add a file and push it to GitHub.
Under your Git repo on your computer, create a new file and add some content to it. HelloWorld.txt
Git doesn’t track all the files in your repo wihtout you telling it which files to track, to do this you need to always update the repo index whenever you add new files in it using the following command.
git add -A
After doing changes to any file, you need to commit those changes to Git to save the current version as a intermediate version. You do this using the commit command.
git commit -m “Commit_Message_to_know_what_you_done_and_for_fellow_devs”
Push to GitHub
You added the file to the index, did changes and comitted them to the repo on your local machine, it is time to push them to your GitHub account.
CONGRATULATIONS! YOUR FILES ARE NOW ON GITHUB
I hope it was an easy introduction, if you have more questions feel free to ask them in the comments. I also suggest watching the Data Scientist’s toolbox course on Coursera, there are four great videos about Git and GitHub.