I am like you, I don’t understand things easily. All tutorials I read on git so many things to me at once e.g git-add, git -commit, git-push, git-remote,git-pull…my brain just got explode 🤯.
To help me do so, I create what I believe the world simplest git tutorial for beginners with the example to get started. For experts, I apologize to you for my unconventional way of introducing git.
Note: This article will focus on simple plain text instead of some hiffty niffty code since the main focus of this article to understand the basics of git and not any specific programming language.
So, let’s get started with this article.
Table of contents:
- A simple definition of Git
- Installation of Git
- Change your default vim text editor associated with Git
- Create the working Directory
- Initialize Git repository inside working Directory
- Let’s write an Essay
- Add essay file content to Git
- Commit the staged Essay file to Git
- Adding A remote repository URL to Git VCS
- Git Push
1. A simple Definition of Git
By far Git is the most widely used Version Control System (VCS) it makes it easy to track files what is changed and it simplifies working on files with multiple peoples. I didn’t say projects because if I did we got scared since we’re dummies.
Let’s take an example and say you’ve written a 500 words essay on How I got promoted after learning Git and you plan to share it on the cloud server for other people to read. Now a person sitting somewhere in Xyz Location makes a copy (clone) of your essay locally on their system and append some changes in it– and (push) the updated essay file on the remote repository.
Now the Git will not blindly update your file. It waits until you accept the changes like, what part has been changed, who did it, why dit it (commit message)?
All your answers inside the Git VCS. It is designed for coordinating work with other people to track changes in any set of files and merges the changes inside the original file. I know there a lot more to explain but I’ll rather explain them with examples so that it is easier to follow.
One thing more before jumping to the next section is that Git isn’t the only version control system out there but by far is the most popular one.
2. Installation of Git
If you have already installed the Git package on your machine, you can happily skip this section.
First things first–you have to install it. You can get the Git from the existing package for your platform. Show me how!
Installing on Linux
If you want to install Git on Linux via binary installer you can do so with basic package management tools that come with your distribution. If you’re on Fedora, run the following command on the bash shell.
yum install git
Or if you’re on Debian-based distribution like Ubuntu try the following command.
apt-get install git
Installing on Mac
The easiest way to install git on Mac is to use the graphical Git Installer, which you can download from the SourceForge page.
Installing on Windows
Installing Git on Windows is very easy. The msysGit project has one of the easiest installation procedures. Simply download the installer exe file from the GitHub page and run it.
3. Change your default vim text editor associated with Git
Did typing on terminal make you feel like a hacker? It’s ok you can admit it. It does feel good but for beginners, it can be terribly scary little thing. You need to remember a lot of
To avoid yourself from potential tears, you could just change the default text editor. Believe me! I’ve been through hard times.
In order to change your text editor to Atom, or Sublime follow the instructions in this GitHub Help.
By the way, I like using Atom when working with Git.
4. Create the working Directory
In your computer create a folder, this is where you work. Let’s called the directory
[email protected]: ~# mkdir essay-writing -v mkdir: created directory essay-writing
5. Initialize Git repository inside working Directory
Now navigate to your local directory which you just created and then add the local Git directory using the following command.
[email protected]: ~# cd essay-writing [email protected]: ~# git init Initializing empty Git repository in essay-writing/.git/
git init creates a hidden folder,
.git where all your internal tracking data for the
essay-writing directory will be stored. Any changes you make inside your working directory will now easy to track.
6. Let’s write an essay
Now, to make things a little bit clear let’s create a file called
git-promotion-essay.txt in the project folder and then add the following text like this:
[email protected]: ~# cat > git-promotion-essay.txt << 'EOF' > Hello reader out there, please learn git it'll be very beneficial for your next promotion. > EOF
Sorry, I make simple things slightly harder and create a
.txt file like a pro 🧙♂️. You can simply open your preferred OS text editor, start writing the essay, and then simply store the file in your working directory.
All very simple so far, I hope 👏👏
7. Add Essay File Content To Git
Putting the file inside the working directory doesn’t magically include it inside the Git VCS. We need to tell the Git magic-box that I want you to add (Stage) this file inside your VCS.
[email protected]: ~# git add git-promotion-essay.txt -v add 'git-promotion-essay.txt'
Wait…did the magic worked? Did Git add my file to VCS? If you’re ever unsure just type
git status in the working directory. This will print some basic information, such as which file has been added to Git recently or has been modified.
[email protected]: ~# git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: git-promotion-essay.txt
Since we’re dummies and get confused easily we should check
git status anytime and it will print additional information depending on what’s currently going on in order to help you out.
In case you want to add (stage) multiple files like a pro instead of adding one-by-one.
[email protected]: ~# git add file1 file2 file3
Or even you want to become a
[email protected]: ~# git add .
Note: Use this carefully, this will add (stage) all your files to be added to Git version control.
⚠ If you️ then go and edit
git add git-promotion-essay.txt
8. Commit the staged Essay File to Git
It’s not all over yet we’ve to commit our essay file to our local repository.
Wait…what? I know, I said at the start of this article we’ll upload the file to the cloud server and now I’m simply saving the file inside the local repository.
Actually, before sending (push) the file to the remote repository we need to commit the changes in our local repository. Believe me on this soon we’ll see the Git magic.
Use the following command to commit the file:
[email protected]: ~# git commit -m "My git promotion essay" [master e70012f] My git promotion essay 1 file changed, 1 insertion(+)
“My git promotion essay” is an optional commit message. It’s like a comment which helps you and other peoples to understand what changes have been done in a particular commit.
9. Adding A remote repository url to Git VCS
Up till now, we haven’t tell Git to push our local repository
essay-writing content into a remote repository. So, to share our local repository we need to create another repository on the remote server.
Fear, not dummies!! there are plenty of websites out there who offers hosting services that let us manage our Git repositories free of cost.
Let me introduced you to Mr.GitHub for our remote repository.
Go to the GitHub home page, create an account if you haven’t had one else simply login into your account, create a remote repository, and finally copy the remote repository url like shown in the image below.
Now, Listen 👂 out dummies!! copy the url of your remote repository, get back to your bash shell where you left out, and point your local repository to remote repository with the following command.
[email protected]: ~# git remote add essayOrigin https://github.com/AhsenSaeed/git-essay-writing.git // replace it with your git remote repo
git remote add command takes two arguments:
- A remote name, for example, essayOrigin
- A remote URL of your remote git repo.
Now if you to want to check out your remote repo URL associated with this local repo you can just type the following command.
[email protected]: ~# git config --get remote.essayOriginal.url // the essayOriginal should be the name of your origin
10. Git Push
Alright, dummies, it’s time to see the magic of Git when all our local repo content will be uploaded to our remote repository.
AND!!! Here is the command.
[email protected]: ~# git push -u essayOrigin master // essayOrigin is your branch name
After hitting the above command on the terminal it’ll ask from you to add your GitHub credentials. After successful authentication, it’ll upload all your local repo content to the remote repo. HURRAY 😍
Here’s the screenshot.
Now other people who wanna read out How You Got Promoted After Learning Git can easily make a copy (clone) of your essay inside their local machine and push the new changes.
DONE!! That’s all, for this article!!! I know that’s not enough but I think a dummy like me needs to first digest this good piece of cake 🍰 . And also my brain needs to rest a bit to continue further. I’ll catch up with you guys in my next article with all remaining commands like git -merge, git -clone, git -pull…., git-branch.
I hope you appreciate this post and it’s helpful for you. Do share it with others and press the ♥️ button at the bottom of this article. Also, if you want to get notified when my new article gets published subscribe to my website at the home page.
Thank you for being here and keep reading…