Git

Introduction to Github

Introduction to Git command line

Posted by Yingshan Li on January 8, 2019

Git is the most popular version control system in the world. In this article, I will introduce some of the most essential commands in git.

Installation

brew install git

Figuring

git config —global user.name “yingshanli”
git config —global user.email “lys_life@163.com”

Connect remote repository

git remote add origin https://github.com/yingshanli/yingshanli.github.io 

### Connect the remote repository with the local repository

Create new repository

mkdir learngit
cd learngit
git init 

### Create a new repository. This command will generate a .git directory to track the repository

Basic commands

vi readme.md (Git is cool!)
git status (The status of current repository,changes not staged for commit)
git diff readme.md (Check what has been changed)
git add readme.md (Submit all files in cache to the repository)
git status (changes to be committed)
git commit -m “readme file”
git status (nothing to commit)

Version backtrack

git log; (check the history)
git reset —hard HEAD^;(HEAD points to the current version,HEAD^ points to the previous version,HEAD^^ points to the one before the previous version,HEAD~n points to the nth version in reverse order)
git reflog; (Record all the commands)
git reset —hard commit_ID; (commit_ID does not need to be complet, only the initial few characters would be enough

Redo edits

git checkout -- file Switch branches or restore working tree files

Delete files

git rm (Delete file)
git rm reame.md 
git commit -m “remove readme.md” (commit the deletion)
git checkout — readme.md (You can cancel the deletion before it is committed)

Synchronize remote repository

git pull
git push -u origin master 
###commit all the updates and new files in the local repository to the remote master branch