Basic:
Create a repository:
git init
Add files to repository to be committed:
git add filename1 filename2 ( add files to stage)
Make files committed
git commit -m "xxx" (commit files to branch)
Check the result
git status
Version Control:
Compare the difference
git diff filename
Show history
git log
or
git log --pretty=oneline
Back to one history version
git reset --hard HEAD^ (HEAD - current version, HEAD^ - last version)
or
git reset --hard commit-id
Discard changes in workplace
git checkout -- filename
Unstage changes
git reset HEAD filename
Undo committed change
git revert HEAD
Delete files from repository
git rm filename
Get the file deleted back
git checkout -- filename
Remote:
Link local repository with GitHub remote repository
git remote add origin git@github.com:xxx (origin - remote repository)
Push files to remote repository
git push -u origin master (first time)
or
git push origin master
Branch:
Create/Switch to a new branch
git checkout -b bname
or
git switch -c bname
Check current branch
git branch
Merge branch to current branch
git merge bname
Delete branch
git branch -d bname
Hide the current workplace
git stash
Get the latest submission
git pull
or
git branch --set-upstream-to=origin/dev dev
git pull