Git and Github Notes

Git fast version control

  • some basic concepts

  • Version management and tracking

  • Version control systems are software tools

  • Can help teams manage source code

Status of Version version status

  • Untracked
  • Tracked
  • Staged has been staged
  • Committed Submitted

HEAD -> master / branch

  • HEAD: Current progress, latest status
  • Master: main line

What git tracks is the changes to the file, not the file itself.

  • Deleting files also requires “add” and “commit”

Files under version management that need to be ignored

  • Add .gitignore in the project directory
  • Write the file suffix or file name that does not require version management control in the .gitignore file

Github is a platform/equivalent to Server

  • Git tool hosts documents or code on the github platform -

Install

Mac os

  • Mac OS comes with git. Enter git -- version to see the git version.

Windows

  • Download the latest https://git-for-windows.github.io/ git for windows
  • Complete the git installation according to the instructions
  • After completing the installation, you can see the git bash icon

Ubuntu /Debian

  • Install according to the command below
$ sudo apt-get update
$ sudo apt-get install git
$ git --version

Use

Basic configuration

Configure git username and email using the following commands

$ git config --global user.name "Your name"
$ git config --global user.email "your_email@example.com"

Basic usage

# 加入 Git
$ git add app.py
$ git add init.py main.py
$ git status
$ git commit -m "初始化,建立 project"

# 查看提交記錄
$ git log
$ git log --oneline

# 比較及還原檔案
$ git diff fd0b510 -- app.py
$ git checkout fd0b510 -- app.py

# 重設版本;此操作不可逆,請先備份
$ git reset --hard 55f7a26

Back up code or documents to github

$ git remote add origin https://github.com/dukehug/{repository}/{project_name.git}
$ git branch -M main
$ git push -u origin main
$ git push

Multi-person collaboration

  • Invite collaborators on github
  • Collaborator clone project to local (clone)
  • The main author pulls the collaborator’s updates to the local (pull)
  • branch management
$ git clone https://github.com/dukehug/{repository}/{project_name.git}
$ git checkout -b branch2
$ git add .
$ git commit -m "新增和更改文件"
$ git push origin branch2
  • There will be 2 branches
  • The collaborator submits a “Pull request” under the branch he is responsible for
  • Collaborators request that these modifications and changes be merged into the master branch
  • The main author can agree or disagree, or request change
  • Agree with the request and “Merge pull request” will be executed.
  • After the merge is completed, the branch2 branch will be deleted.
  • Every time you update the remote code or files, you need to execute pull

Reference:

https://youtu.be/FKXRiAiQFiY?si=QP6wm_S9diztgIWm - Essential skills for program and web developers! Quickly get started with Git and GitHub without any basic knowledge, and easily master the key to version control! - papaya computer classroom

https://www.atlassian.com/zh/git/tutorials/atlassian-git-cheatsheet - Git cheat sheet

https://git-scm.com/docs - Complete list of all commands

https://education.github.com/git-cheat-sheet-education.pdf - Github GIT CHEAT SHEET - Github education