ติดตั้ง Git บน CentOS 7

ติดตั้ง Git

Install Git with Yum

sudo yum install git

Install Git with apt

sudo apt install git

ตรวจสอบการติดตั้ง

git --version

Set Up Git

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Checking Your Settings

git config --list

You can view all of your settings and where they are coming from using:

git config --list --show-origin

Your default branch name

By default Git will create a branch called master when you create a new repository with git init. From Git version 2.28 onwards, you can set a different name for the initial branch.

git config --global init.defaultBranch main

Getting a Git Repository

Initializing a Repository in an Existing Directory

cd /home/user/my_project
git init
git add *.c
git add LICENSE
git commit -m 'Initial project version'

Cloning an Existing Repository

You clone a repository with git clone <url>. For example, if you want to clone the Git linkable library called libgit2, you can do so like this:

git clone https://github.com/libgit2/libgit2

If you want to clone the repository into a directory named something other than libgit2, you can specify the new directory name as an additional argument:

git clone https://github.com/libgit2/libgit2 mylibgit

Recording Changes to the Repository

Checking the Status of Your Files

git status

ถ้าจะให้แสดง diff (staged) ด้วยก็

git status -v

หรือถ้าจะดูสรุปสั้นๆก็

git status -s
$ echo 'My Project' > README
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    README

nothing added to commit but untracked files present (use "git add" to track)

Tracking New Files

git add README
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)

    new file:   README

Ignoring Files

$ cat .gitignore
*.[oa]
*~

Viewing Your Staged and Unstaged Changes

To see what you’ve changed but not yet staged, type git diff with no other arguments:

git diff

If you want to see what you’ve staged that will go into your next commit, you can use git diff --staged or git diff --cached.

git diff --staged

หรือ

git status -v

Committing Your Changes

git commit -m "Story 182: fix benchmarks for speed"