Tools

Useful Git Commands Cheatsheet

17 กันยายน 20222 นาที
0
Useful Git Commands Cheatsheet
Table of Contents

Initializes

Initializes a new Git repository

Bash Logo
git init

Add files

ในการเพิ่มไฟล์เข้าไปในสถานะ staging area เราจะใช้คำสั่ง

Bash Logo
git add <files>

แล้วตามด้วยชื่อไฟล์ที่ต้องการเพิ่ม แต่ถ้าเราต้องการเพิ่มทุกไฟล์ทุกโฟลเดอร์ สามารถใช้คำสั่ง

Bash Logo
git add .

เพื่อเพิ่มทุกไฟล์ทุกโฟลเดอร์เข้าไปใน staging area ได้

Reset

Undo the changes to the local files, and restore to the last commit.

Bash Logo
git reset

Show Log

Used to view the entire commit history.

Bash Logo
git log

Commit

Used to commit files (locally) on the repository.

Bash Logo
git commit -m "message"

Clone

Used to download existing code from a remote repository.

Bash Logo
git clone <url>

Work with Branch

Used to list all the local branches on the machine.

Bash Logo
git branch

Create new Branch

Used to create a new branch locally.

Bash Logo
git branch <branch-name>

Delete Branch

Used to delete a branch.

Bash Logo
git branch -d <branch-name>

Rename Branch

Used to rename the current working branch.

Bash Logo
git branch -m <new-name>

Merge Branch

Merges the provided branch with the current working branch.

Bash Logo
git merge <branch-name>

Switch Current Branch

Used to switch from the current branch to another one.

Bash Logo
git checkout <branch-name>

Switch and Create new Branch

Creates a new branch and switches to the new one.

Bash Logo
git checkout -b <branch-name>

Push

Used to save all commits to the remote repository.

Bash Logo
git push <remote> <branch-name>

Pull

Used to pull down all the updates from the remote repository.

Bash Logo
git pull <remote>

Remove

Used to remove a file from the working directory.

Bash Logo
git rm <file-name>

Stash

Used to temporarily remove uncommitted changes.

Bash Logo
git stash

See Difference

Displays the difference between files in two commits or between a commit and your current repository.

Bash Logo
git diff
Tags:Git

คลิกเพื่อแสดงความคิดเห็น