Git and GitHub for Beginners I(Tutorial)

PJ Wang
PJ Wang
Nov 6, 2017 · 5 min read

What is Git?

Git is a version control system for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for source code management in software development,[8] but it can be used to keep track of changes in any set of files. As a distributed revision control system it is aimed at speed, data integrity, and support for distributed, non-linear workflows.[1]

Why Git?

Version control is the only reasonable way to keep track of changes in code, manuscripts, presentations, and data analysis projects. I used to make numbered tar.gz files for a project. But exploring the differences is difficult, to say the least. And if you use git properly, you’ll have annotated each small change.

Merging collaborators’ changes made easy. Have you ever had to deal with a collaborator sending you modifications distributed across many files, or had to deal with two people having made changes to the same file at the same time? Painful. git mergeis the answer. [3]

Install Git

Open terminal and code the scripts

$ sudo apt-get install git-all

Download link: Click

Download link: Click

SourceTree: Click


Desktop user$ mkdir gitDemo
Desktop user$ cd gitDemo
gitDemo user$ git config --global "daniel wang"
gitDemo user$ git config --global ""

Check your config

gitDemo user$ git config --list
gitDemo user$ git init

Generate a hidden directory “.git” in your directory

.DS_Store is a file that stores custom attributes of its containing folder, such as the position of icons or the choice of a background image.

Type the command:

user$ defaults write AppleShowAllFiles TRUE;\killall Finder

However, if you want to hide hidden files

user$ defaults write AppleShowAllFiles FALSE;\killall Finder
Work Flow

Workspace: What you see in your editor and where you make your changes.

Staging Area: A snapshot of your working tree at a particular point in development.

Local Repository: Your copy of a project, initialized as a Git repository.

Remote Repository: The shared copy of the repo that lives on a remote server.

Clone files from github

gitDemo user$ git clone

Or add files from local

gitDemo user$ echo test123 > testFile.txt
gitDemo user$ git status

New file is “Untracked files” before execute “git add”.

gitDemo user$ git add testFile.txt
gitDemo user$ git status

After the first time you add file, you could remove file and back to “workspace” by following instruction.

gitDemo user$ git reset HEAD testFile.txt

Or you could commit it with message.

gitDemo user$ git commit -m "Add testFile.txt"
gitDemo user$ git status

You could amend the message about last commit.

gitDemo user$ git commit --amend

If you regret to commit, you could go back to previous version.

gitDemo user$ git reset --hard HEAD^

The last three commits (HEAD, HEAD^, and HEAD~2)

This command creates a new commit that undoes the changes from a previous commit. This command adds new history to the project (it doesn’t modify existing history).

Add and commit the file named “testFile2.txt”, and execute the command.

gitDemo user$ git revert HEAD
gitDemo user$ git log

This command is back to previous version including log.

Add and commit the file named “testFile2.txt”.

gitDemo user$ git log

Type the command, and the file can not recover.

gitDemo user$ git reset --hard HAED^
gitDemo user$ git log

If you don’t want to delete the file, type other command:

gitDemo user$ git reset --soft HEAD^
gitDemo user$ git status
gitDemo user$ git reset --mixed HEAD^
gitDemo user$ git status

Tag the last commit version.

gitDemo user$ git tag -a v1.0 -m "version 1.0"
gitDemo user$ git show v1.0

Tag any version you want

First, check which version you want to tag.

gitDemo user$ git log --pretty=oneline

Second, type the command:

gitDemo user$ git tag -a v1.0 6c32c24 -m "version 1.0"
gitDemo user$ git log --pretty=oneline

If you want to delete tag, type the command:

gitDemo user$ git tag -d v1.0

How to use branch?

How to use GitHub?

CS Note

Some note about CS

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store