Git

Version Control

Git vs Other VCS

Concepts

Three States

  1. Modified: changed the file but have not committed it to your database yet
  2. Staged: marked a modified file in its current version to go into your next commit snapshot
    *
  • add take changes into the control of git
  1. Committed: the data is safely stored in your local database

Commit

Someone make some changes, then they commit to annotate the history of changes. Once committed, a "snapshot" was taken of the differences made to the system at a given point in time.

Push & Pull

When collaborating (even with yourself), you may want to host a remote repository (repository is just a folder of your project) that can accessed by anyone. Push is just submitting your commits (changes with annotations) to the remote; while pull is the opposite.

Branches

In a large collaborating project, you may have different lines of work that have different focus and progress. Then you create branches, which leave the main (used to called master 😆) branch at some point and will eventually merge to the main branch.

In essence, when a branch gets merged into master, its commits get added to the top of the master history.

Other

Usage

Update

On Linux

sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git

Configuration

git config --global user.name "Your Name"
git config --global user.email "yourname@example.com"
git config --global init.defaultBranch main

SSH Management

ssh-keygen -C "hello@gmail.com"
cat ~/.ssh/id_rsa.pub | clip.exe
ssh -T git@github.com

Workflow

# Initialize a repo
git init
# Clone a repo
git clone <repo_url>
# Stage all changes in the **directory**
git add .
# Stage all changes in the **repository**
git add -A
# Commit
git commit -m "commit message"
# Check status
git status
# Push
git push [-u origin main]
# See history
git log
Rmk

  • origin is the remote name
  • main is the brach name

Creative Commons License by zcysxy