If you are a beginner in the field of programming you must have come across the term
Git from blogs or even tutorials and wondered what they are🤔, in this blog I intend to explain them and hopefully you will get an idea of what they are and how they work.
GitHub is a code hosting platform for
version control and
collaboration. Simply put, GitHub is a cloud storage platform like Google Drive or OneDrive but is built and centred around code.
Apart from just storing your code. GitHub allows you to collaborate with other programmers on projects simultaneously and remotely making it accessible from anywhere in the world.
In my intro I used the word
version control. And this is where Git comes in. GitHub not only just stores your code. It keeps track of every single change you make and commit, that way if you ever need to go back to a specific point in time of your project you can easily do so.
Git is a version control system(VCS), it is in charge of tracking your source code or files for any changes made during development. Git operates locally, therefore has to be installed and linked with your GitHub account through a remote in order for it to access your projects and update them accordingly.
In this tutorial I will teach you some of the basics you need when using Git or GitHub
Create a repository on GitHub.
Sign in into your account or create one if it's your first time. Click on the
+icon to create a new repository
Enter a name for your repository. Use hyphens instead of spaces. You can add an optional Description as well.
Check ✅ the
initialize this repository with a README. This will allow you to be able to download/clone the repository to your local computer.
Clone the repository to your computer. To clone your repository. Click on the
codebutton. Copy the link of your project using the clipboard icon.
To clone the repository to your computer. Open the terminal or git cli on your computer depending on what OS you use and run
If the command is not recognised then download git from https://git-scm.com
Navigate to the directory you would like to clone your project in and run
git clone followed by the link to your repository.
git clone https://github.com/inezabonte/first-app.git
Commits are snapshots of changes made to your project. Each change you commit is referenced with a unique alphanumeric code that can be used if you ever need to go back to a specific commit.
In order to make changes to our repository. Open the cloned repository in a text editor and let's make some changes to our README file.
After saving your changes, go back to terminal and navigate to your project. After that run;
git status shows us which files have been changed, which files are tracked, etc. As you can see below, it tells us that there is a file that has been
modified which is the README.md file
In order to push our changes to GitHub, we need to:
Stage Changes for commit. To do this we use the command
git addfollowed by the file you want to add.
git add README.md
Commit with a message. This is done using the
git commit -mcommand followed by a short message in quotes explaining the changes you made, to whoever might be looking at the project.
git commit -m "My first commit"
Push to GitHub. Finally we can now push our changes to GitHub. To do this we use the command
git push origin master
git push origin master
NB If this is your first push you may be required to enter your GitHub
password. It's a one-time process.
The lines highlighted in green show the additions that you made in your commit. Deletions are highlighted in red.
I hope this tutorial has been of help to you. If you find yourself forgetting some of the codes, don't worry you can google them or also use this Cheatsheet.
If you need further clarification, you can ask in the comments and I'll be sure to get back to you.