Master the beauty of Git

Start your software development journey with 7 simple Git commands

Have you ever wondered how to learn Git? You have been stumbling with Git for a long time. In the end, you always need to master its tips. This is the reason why I wrote this article, I will take you to the journey of enlightenment. Here is my basic guide on how to speed up the Git learning process. I will cover the actual situation of Git and the 7 Git commands I use the most. This article is intended for interested developers and freshmen who need an introduction to Git and how to master the basics.

You can continue reading the entire article, or read-only TLDR; in part, although this will hurt me.


In the process of learning Git, please develop the habit of following these steps:

  1. Feel free to use git status!
  2. Just change the files that you really want to change.
  3. Git add -A will be your friend.
  4. Feel free to use the command git commit -m “meaningful messages”.
  5. Use the command git pull before doing any push, but this will need to be done after you have made some changes.
  6. Finally, git push pushes the submitted changes.


For any developer, the first step is usually to choose a widely used place to host his or her code base. That is, GitHub . It is the gathering place for everything about the code. To understand the concept of GitHub, you first need to know what Git is.

Git is a command-line based version control software with several desktop applications available on Windows and Mac systems. Git was developed by Linus Torvalds, the father of Linux, and Linus Torvalds is one of the most influential people in computer science. Because of this advantage, Git has become the standard for most software developers to share and maintain code. Let’s take a closer look at this big paragraph. As its name suggests, the version control software Git lets you preview all versions of the code you’ve written. Literally, each code base of the developer will always be stored in its own repository. The repository can be called any name, from pineapple to express. In the process of developing code in this repository, you will make numerous changes until the first official release. This is the core reason why version control software is so important. It gives developers as a clear understanding of all the changes, fixes, and improvements made to the code base. On the other hand, it makes it easier to collaborate, download the code for editing, and then upload the changes to the repository. However, despite so many benefits, there is one more thing that can be added. You can download and use these files, even if you have done nothing during the entire development process.

Let’s go back to the GitHub section of the article. It is just a hub for all warehouses that can be stored and viewed online. It is a place where people with common interests can get together.

A thousand miles begins with a single step

OK, remember, Git is a piece of software. Like any other software, you first need to install it:

Git – Install Git, if you want to install Git from source, you need to install these Git dependencies: autotools – from

Tips: Please click on the link above and follow the instructions.

The installation process is complete, very good. Now you need to type in your browser address bar Visit the website. If you don’t have an account yet, you need to create a new account. This is where you dance. Log in and create a new repository, named Steve, for no reason, just want a store named Steve to be fun. Check the “Initialize this repository with a README” checkbox and click the Create button. Now you have a warehouse called Steve. I believe that you will be proud of yourself.

Start using Git now

Now is the more interesting part. You will clone Steve to your local machine. Think of this process as copying the repository from Github to your computer. Click on the “clone or download” button and you will see a URL similar to the following:

Copy this URL and open a command prompt window. Now enter and run the bar command:

git clone

Abrakadabra! The Steve repository has been automatically cloned to your computer. Look at the directory where you cloned this repository and you will see a folder called Steve. This local folder is now linked to its “origin”, which is the remote repository on GitHub.

Keep in mind this process, and you will repeat this process many times during the career of your software development engineer. Once you’ve completed all of this preparation, you’re ready to start using the most common and commonly used Git commands.

You are now using Git in real scenes.

Locate the Steve directory and open a Command Prompt window in that directory, run the following command:

git status

This will output the status of your working directory, letting you know all the files you have edited. This means it shows the file differences between the remote library and the local working directory. The status command is used as a template for the commit, and I will talk about commit later later in this tutorial. Simply put, [git status][1] tells you which files you have edited to give you an overview of what you want to upload to the remote library.

However, before you do any uploads, the first thing you need to do is select the files you need to send back to the remote library. Use the following command to complete:

git add

Then create a new text file in the Steve directory, you can take a fun name pineapple.txt. Write whatever you want in this file, return to the command prompt, and type git status again. Now you will see this file appear in red under the tag “untracked files”.

On branch masterYour branch is up-to-date with 'origin/master'.Untracked files:  (use "git add <file>..." to include in what will be commited)pineapple.txt

The next step is to add it to the staging area. A staging area can be thought of as an environment in which all changes you have made are bundled as a change and submitted when submitted. Now you can add this file to the staging area:

git add -A

The -A option means that all files you have changed will be added to the staging area for submission. However, git add is very flexible, it can also be added as a file like this:

git add pineapple.txt

This approach gives you the ability to choose every file you want to stage without worrying about adding something you don’t want to change.

Run git status again and you will see the following output:

On branch masterYour branch is up-to-date with 'origin/master'.Changes to be committed:  (use "git reset HEAD <file>..." to unstage)new file:   pineapple.txt

Ready to submit changes? let’s start.

git commit -m "Write your message here"

Git commit The command stores the file stored in the staging area along with the log information from the user describing the change in a new location. The -m option adds information written in double quotes.

Check the status again and you will see:

On branch masterYour branch is ahead of 'origin/master' by 1 commit.  (use "git push" to publish your local commits)nothing to commit, working directory clean

All changes are now added to a commit and there will be a message related to your work. Now you can push this commit to the remote library “origin” with git push. This command is literally saying that it will upload your submitted changes from the local machine to GitHub’s remote repository. Return to the command prompt and run:

git push

You will be asked to enter your GitHub account number and password, and you will see something like this:

Counting objects: 3, done.Delta compression using up to 4 threads.Compressing objects: 100% (2/2), done.Writing objects: 100% (3/3), 280 bytes | 0 bytes/s, done.Total 3 (delta 0), reused 0 (delta 0)To   c77a97c..08bb95a  master -> master

That’s it. You have successfully uploaded your local changes. Take a look at your repository on GitHub and you will see that it now contains a file called pineapple.txt.

If you are a member of a development team? What happens if they push to submit to “origin”? This is when Git really starts to play its magic. You can easily bring the latest version of the codebase with a simple command. pull Go to your local machine:

git pull

But Git also has a limit: you need to have a matching version to push to “origin”. This means that your local version needs to be roughly the same as the original version. When you pull files from “origin”, there can be no files in your working directory, as they will be overwritten during this process. So I gave this simple suggestion. In the process of learning Git, please develop the habit of following these steps:

  1. Feel free to use git status!
  2. Just change the files that you really want to change.
  3. Git add -A will be your friend.
  4. Feel free to use the command git commit -m “meaningful messages”.
  5. Use the command git pull before doing any push, but this will need to be done after you have made some changes.
  6. Finally, git push pushes the submitted changes.

Hey! Are you still reading this article? You have been watching it for a long time, take a break!

Are you resting? Ok! Let’s handle some errors. What if you accidentally changed some files that you should not change? Don’t worry, just use git checkout . Let’s change something in the file pineapple.txt: add a line to the file, say “Steve is mega-awesome!”. Then save your changes and check with git status:

As expected, it has been recorded as a change. But what if Steve isn’t really good? What if Steve is bad? do not worry! The easiest way to restore changes is to run the command:

git checkout -- pineapple.txt

Now you will see that the file has been restored to its previous state.

But what if you play it? I mean, things have become confusing and I need to reset everything to the same state as “origin”. Don’t worry, in this emergency we can enjoy the beauty of Git:

git reset --hard

git reset The command along with the –hard option can discard all changes since the last commit, and sometimes it works.

Finally, I want to encourage you to use Git as much as possible. This is the best way to learn how to use it skillfully. In addition, develop the habit of reading Git documents. There may be some clouds in the beginning, but after a while you will understand its tips.

I hope that you (lady and girls) will be as happy as I was when I read this article. If you think this article is useful to others, you can share it with others. Or, if you like this article, you can like it below so that more people can see it.


Author: Adnan Rahić Translator: zhousiyu325 Proofreading: wxy

This article LCTT Original compilation, Linux China Honor launch