Implement nice teamwork with Git and Github

Francabel
5 min readMay 4, 2020

--

Git is a powerful tool to do version control. There are two key features of Git, one is a great system for history tracking, and the other one is for collaboration. I believe you might see some example on the Internet. In the past, we did the version control via different file name. It might be ok for one-man team, but not for multiplayer team. It causes tons of untraceable history and inefficient teamwork. Like sometimes you revise app2, but the next your colleague revise app2 again.

In fact, you do not worry about the above situation would happen on you because of Git and GitHub. I would like to share some command line use frequently and the step for git usage.

Git is an open-source version control system, we can easily realize the history of your project, including who, when, and what is revised. When using it, you can use Git bash. It looks like the Commend prompt on Windows.

Git Initiation (git init)

The very first command of Git is to initialize Git repository, then you have an empty repository. In other words, it is a Git project that can have multiple files associated with it.

Connect your name and email (git config — global user.name “your name”/user.email “your email”)

The reason why we connect to our name and email is that everyone can check who does the revision or change. Every change will be recorded and shown clearly, so we can track it.

Add file to staging area (git add .)

Each stage of Git

In Git world, there are three areas, working directory, staging area, and repository. When you create files, all of them are in the working directory. You can see staging area as a box where you put things in before storing in your warehouse (repository). So, if you want to put all files into the staging area, you can use git add .

Check the status of the staging area (git status)

After adding files to your staging area, you can use git status to check whether files are successfully put or not.

Commit things in the box (git commit -m/ git commit -am)

When you put something in the staging area, you need to commit this action, like make a record and help other people understand what addition or revision is. If stuff in the staging area is not the first time you put into, you can use git commit -am, so that you can don’t need to use git add.

Check the history of commit (git log/git log — oneline)

git log is a command which helps you to clearly see the history of your commit, including commit number (We will take a look it after), commit author, and when the author create commits. If you would like to see lite version history, you can use git log — oneline.

OMG, there is a typo in my commit (git commit — amend)

Typo of html’s file name
Make revision of file name
After changing the commit

The command of git commit –amend can help you revise the commit you just made.

I don’t want the commit I just committed (git reset HEAD^ — hard/ — soft)

The log after soft reset
The log after hard reset
The folder after hard reset

Sometimes, you do not want the commit you made, maybe you want to commit the files later. There are two way to do that and that are git reset HEAD^ — hard/ — soft. Let’s take a look at — soft. When you use git reset HEAD^ — soft, the commit you just made will be removed, but the file or change still exist. However, git reset HEAD^ — hard is that every change you made, including commit and file) will be removed.

I don’t want the change I just added(git restore)

After git restore, h3 tag has been remove

The command git restore can help you discard changes which is in the working directory. As you can see, the h3 tag has been removed after you use git restore.

This article is to help you create a basic concept for how to use Git and share some command that using very frequently. In the next article, we will go through branch concept of Git.

Hoping this is helpful for you and see you next time.

Reference to Lidemy and The Coding Train

--

--

Francabel
Francabel

Written by Francabel

從業務轉換跑道,目前正朝著前端工程師邁進,寫code是生活,是工作,也是態度。轉職是一段旅行,享受旅行的過程,並指引到夢想處

No responses yet