(Git_1) Start to Git

Introduction

Git is the most popular version control system.

Why

We need version control to track changes and identify why key decision were made along the way.

(How) Before Git

Install

On mac, use homebrew to install git

$ brew install git

Check the version of git

$ which git

or

$ git --version

Setting

check current setting

$ git config --list

add global setting

To change the setting that fit into ‘all’ project,

$ git config --global user.name "the name you want"

or

$ git config --global user.email "xxx@yyy.com"

add specific setting

To change the setting only being used in specific project

$ git config --local user.name "the name you want"

or

$ git config --local user.email "xxx@yyy.com"

(How) Start to Git

initializing git

To start version control with git in current directory

$ git init

remove git

If you want to remove git on your directory

$ rm -rf .git

Then we can input following to check whether there is file related to git

$ ls -al

Check status

In git, there are three stages (working/stage/history) and the following process: working -> git add -> staged -> git commit-> history

$ git status

create a file for git status testing

$ echo "hello.git" > welcome.html

Then check status again

There is a file, welcome.html, still untracked in git

Add file to temp

$ git add welcome.html

then check status

$ git status

Store the files

store it directly without vim

$ git commit -m "the message to note to this commit"

or open vim to type in message we want

$ git commit

View the historical commits

$ git log

If we want a neat overview:

$ git log --oneline --graph

Find key word in commits’ message

$ git log --oneline --grep='wtf'

Find key word in commits’ title

$ git log -S 'Ruby'

Find commits’ in a time range

$ git log --online --since="9am" --until="12am"

Find commits for specific file

for example, if we want to read the commit message of specific file, wtf.html

$ git log wtf.html

or if we want to know the historical changes of a specific file

$ git log -p wtf.html

Use GUI — SourceTree

With Graph, we can have more clear overview to the git branches

reference:

--

--

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