Tổng hợp các câu lệnh GIT thường dùng GIT#1
Git Bash Commands Cheat Sheet
Setup
git config --global user.name “[firstname lastname]”# Set a name that is identifiable for credit when review version historygit config --global user.email “[valid-email]”# Set an email address that will be associated with each history markergit config --global color.ui auto# Set automatic command line coloring for Git for easy reviewinggit config --global --list# List all Git configuration settings
Repository Initialization
git init# Initialize a new Git repositorygit clone <url># Initialize a new Git repository
Stage & Snapshot
git status# Check the status of your repogit add <file># Add a file to the staging areagit reset <file># Remove a file from the staging areagit commit -m "<message>"# Commit changes with a message
Inspect & Compare
git log# View commit historygit log --oneline# View commit history in compact formatgit log --oneline -n <amount># View commit history in compact formatgit log <branch1> <branch2># show the commits on branch1 that are not on branch2git log --stat -M#git diff# Show changes between working directory and the last commitgit diff <branch1> <branch2># Show changes between two branchesgit show <commit># Show changes made in a specific commit
Branch
git status# Check the status of your repogit branch# List all branchesgit branch <branch># Create a new branchgit checkout <branch># Switch to a branchgit checkout -b <branch># Create and switch to a new branchgit branch -d <branch># Delete a branchgit branch -r# List remote branchesgit branch -a# List local and remote branchesgit branch -u <upstream-branch># Set upstream branch for the current branchgit branch -m <old-name> <new-name># Rename a branchgit branch --merged# List branches that have been merged into the current branchgit branch --no-merged# List branches that have not been merged into the current branch
Merge
git merge <branch># Merge changes from different branchesgit merge --abort# Abort an ongoing merge operationgit merge --squash <branch># Squash the commits from a branch into a single commitgit merge --no-ff <branch># Merge with a merge commit even if it's a fast-forward merge
Rebase
git rebase <branch># Apply any commits of current branch ahead of specified onegit rebase --abort# Abort an ongoing rebase operationgit rebase --continue# Continue a paused rebase operationgit rebase --skip# Skip a conflicting commit during rebase
Cherry-pick
git cherry-pick <commit># Apply a specific commitgit cherry-pick --continue# Continue a paused cherry-pick operationgit cherry-pick --abort# Abort an ongoing cherry-pick operation
Undoing Changes
git reset# Reset staging area to match the last commitgit reset <file># Remove a file from the staging areagit reset --hard# Discard all changes since the last commitgit reset --hard [commit]# Clear staging area, rewrite working tree from specified commit
Remote Repositories
git remote add origin <url># Connect local repo to remotegit push -u origin <branch># Push changes to remote branchgit pull# Pull changes from remote repogit clone <url># Clone a remote repositorygit remote -v# List remote connectionsgit remote rm <remote># Remove a remote connectiongit fetch# Fetch updates from remote repo without merginggit remote show <remote># Show details about a remote repositorygit remote rename <old-name> <new-name># Rename a remote repositorygit push --tags# Push all tags to remote repositorygit push --force# Force-push changes to the remote repositorygit push origin --delete <branch># Delete a remote branchgit pull --rebase# Pull and rebase the current branchgit fetch# Fetch updates from all remote repositoriesgit fetch --all# Fetch updates from remote repogit remote update# Update remote-tracking branches
Stashing (Temporary Commits)
git stash# Save changes for latergit stash list# List stashed changesgit stash apply# Apply stashed changesgit stash drop# Remove a stashgit stash pop# Apply and remove the latest stashgit stash branch <branch># Create a new branch and apply a stashgit stash save "<message>"# Save changes with a custom stash messagegit stash clear# Remove all stashed changesgit stash apply <stash># Apply a specific stashgit stash drop <stash># Remove a specific stash
All rights reserved