What is Git, How to Start Working With GitHub–a Beginner Friendly Overview
It looks like everybody in the tech world is using GitHub. Wondering if you need it too? Let’s have a brief beginner-friendly overview to see what Git and GitHub are and how you can start working with them right away.
What is Git?
We are going to start with defining what Git is and how you can benefit from it. Git is an open-source distributed version control system. What does this mean in simple terms?
Basically, Git is a content tracker. Due to its features, it is usually used to store code. Even more, it is used to store multiple versions of code, maintaining a history of what changes have happened. As a distributed version control system, Git has a remote repository stored on a server and local repositories stored on developers’ computers. Thus, thanks to Git:
- several developers can modify code in parallel;
- it is always possible to go back to an older version of code.
To start working with Git, you’ll need to install it on your computer.
What is GitHub?
GitHub is basically a code-hosting platform, where developers store their projects, collaborate, and network with one another. Using Git without the GitHub interface requires some technical expertise, while GitHub is so user-friendly that it is quite often used even by non-developers to manage different types of projects.
For better understanding, let’s see how you can benefit from GitHub as an aspiring data scientist or software developer.
- First, your profile on GitHub is perfect for storing and presenting your project portfolio—it shows your own projects and your contributions to other projects.
- Second, it is a great place for networking with like-minded people. There are millions of public projects stored on GitHub, and you can find projects that you are interested in and that you can contribute to. You don’t need to contact developers via email and convince them that you can make a valuable contribution. Instead, you can simply “copy” their project by forking their repository, create a better version of the original project, and then demonstrate your work to the original developers by creating a pull request.
To start enjoying GitHub features, you will first need to sign up for an account.
In the next few sections, I’ll provide brief introductions to Git and Github for beginners. In particular, we’ll see how you can store your projects on GitHub, as well as make and track changes. Actually, you can do most of the things directly on the GitHub website, which has a very friendly user interface. Alternatively, you can use terminal commands for managing your projects—this approach is a bit more challenging for beginners but makes things much faster. We will briefly cover both approaches here.
Creating a New Repository
You can start your GitHub experience by creating a repository. This is the place where all the files related to your project are stored. It isn’t necessarily limited to code—you can store all kinds of files in your GitHub repository including images, videos, datasets, etc.
To create a repository, you just need to:
- click the “+” button in the top-right corner and select “New repository”;
- give your repository a name and write a description, if you want;
- select if your repository will be private or public;
- check the box for initializing the repository with a README file.
It is highly recommended to include a README file as it is the first thing people see when they access your repository and it’s a great place to put all important information on the project. Usually, a README file explains what a project is about, why it is useful, how you can get started with a project, etc. If you want this project presentation to look nice and professional, make sure to follow GitHub’s Guide to Mastering Markdown.
Furthermore, while a README file placed into your repository’s root will be a “front page” for your entire project, you can also place these files into the sub-directories of your project to have such informational screens wherever you need them.
Now you are ready to upload and edit files right from your repository on the GitHub website. If you prefer working on your local computer, you can simply download the repository by clicking on the “Clone or download” button and selecting “Download ZIP”.
Let’s also practice adding files to your project using terminal commands.
Setting up an Environment for Working with Git
I assume you have already installed Git on your computer. Now you’ll need to provide Git with your:
- name:
git config --global user.name "name" - email:
git config --global user.email "email"
Make sure that you include here the same email you used for signing up on GitHub.
Adding an Existing Project to GitHub Using the Command Line
After you have downloaded your new repository, you can see it as a folder on your local computer. Now copy or move your existing project to this folder.
Let’s see how you can now add this project to your GitHub repository:
Change the current working directory to the folder with your project:
cd my_project
Initialize this folder as a Git repository:
git init
Now you can add the files to the staging environment. To add all files, use:
git add .
or
git add –all
To add specific files use:
git add file_name
The next step is to package the files into a commit. You do this with the following command:
git commit -m “your_message”
The message at the end of the commit command should explain what the commit contains. For example, you can say “My first commit” or “Fixing bug in the display_image() function” etc.
Now you need to add the URL for the remote repository where your local repository will be pushed:
git remote add origin URL
Here I show where you can get the URL of your remote repository to add to the code above. The button near the URL copies it to the clipboard.
With the next command, you can verify that the remote URL is set correctly:
git remote -v
Finally, you need to push the files from your local computer to the remote repository on GitHub:
git push origin master
This command will push the changes to the master branch of your remote repository.
Now all the files from your local project folder have been added to your remote repository. For example, the Vertabelo project originally contained only a README.md file, but now it also contains some code and image files:
Tracking Changes With Git
You can just work on the project on your local computer: add files, change files, delete files. If you want these changes to be pushed to the remote GitHub repository, you will need only three command lines:
git add .
orgit file_name
to add files to the staging environment.git commit -m “message”
to commit the changes and explain them in the commit message.git push
to push the changes to the remote repository.
Let’s Create Your First Project on GitHub!
Now you know how to start working with GitHub. It’s time for practice! Take one of your projects stored on your local computer and introduce it to the world.
If you want to create really impressive projects, master your skills with Vertabelo Academy’s SQL, Python, and R courses. Success is all about continuous effort and lifelong learning. Good luck!