+5

Tổng hợp các câu lệnh GIT thường dùng GIT#1

Git Bash Commands Cheat Sheet

Setup

  1. git config --global user.name “[firstname lastname]” # Set a name that is identifiable for credit when review version history
  2. git config --global user.email “[valid-email]” # Set an email address that will be associated with each history marker
  3. git config --global color.ui auto # Set automatic command line coloring for Git for easy reviewing
  4. git config --global --list # List all Git configuration settings

Repository Initialization

  1. git init # Initialize a new Git repository
  2. git clone <url> # Initialize a new Git repository

Stage & Snapshot

  1. git status # Check the status of your repo
  2. git add <file> # Add a file to the staging area
  3. git reset <file> # Remove a file from the staging area
  4. git commit -m "<message>" # Commit changes with a message

Inspect & Compare

  1. git log # View commit history
  2. git log --oneline # View commit history in compact format
  3. git log --oneline -n <amount> # View commit history in compact format
  4. git log <branch1> <branch2> # show the commits on branch1 that are not on branch2
  5. git log --stat -M #
  6. git diff # Show changes between working directory and the last commit
  7. git diff <branch1> <branch2> # Show changes between two branches
  8. git show <commit> # Show changes made in a specific commit

Branch

  1. git status # Check the status of your repo
  2. git branch # List all branches
  3. git branch <branch> # Create a new branch
  4. git checkout <branch> # Switch to a branch
  5. git checkout -b <branch> # Create and switch to a new branch
  6. git branch -d <branch> # Delete a branch
  7. git branch -r # List remote branches
  8. git branch -a # List local and remote branches
  9. git branch -u <upstream-branch> # Set upstream branch for the current branch
  10. git branch -m <old-name> <new-name> # Rename a branch
  11. git branch --merged # List branches that have been merged into the current branch
  12. git branch --no-merged # List branches that have not been merged into the current branch

Merge

  1. git merge <branch> # Merge changes from different branches
  2. git merge --abort # Abort an ongoing merge operation
  3. git merge --squash <branch> # Squash the commits from a branch into a single commit
  4. git merge --no-ff <branch> # Merge with a merge commit even if it's a fast-forward merge

Rebase

  1. git rebase <branch> # Apply any commits of current branch ahead of specified one
  2. git rebase --abort # Abort an ongoing rebase operation
  3. git rebase --continue # Continue a paused rebase operation
  4. git rebase --skip # Skip a conflicting commit during rebase

Cherry-pick

  1. git cherry-pick <commit> # Apply a specific commit
  2. git cherry-pick --continue # Continue a paused cherry-pick operation
  3. git cherry-pick --abort # Abort an ongoing cherry-pick operation

Undoing Changes

  1. git reset # Reset staging area to match the last commit
  2. git reset <file> # Remove a file from the staging area
  3. git reset --hard # Discard all changes since the last commit
  4. git reset --hard [commit] # Clear staging area, rewrite working tree from specified commit

Remote Repositories

  1. git remote add origin <url> # Connect local repo to remote
  2. git push -u origin <branch> # Push changes to remote branch
  3. git pull # Pull changes from remote repo
  4. git clone <url> # Clone a remote repository
  5. git remote -v # List remote connections
  6. git remote rm <remote> # Remove a remote connection
  7. git fetch # Fetch updates from remote repo without merging
  8. git remote show <remote> # Show details about a remote repository
  9. git remote rename <old-name> <new-name> # Rename a remote repository
  10. git push --tags # Push all tags to remote repository
  11. git push --force # Force-push changes to the remote repository
  12. git push origin --delete <branch> # Delete a remote branch
  13. git pull --rebase # Pull and rebase the current branch
  14. git fetch # Fetch updates from all remote repositories
  15. git fetch --all # Fetch updates from remote repo
  16. git remote update # Update remote-tracking branches

Stashing (Temporary Commits)

  1. git stash # Save changes for later
  2. git stash list # List stashed changes
  3. git stash apply # Apply stashed changes
  4. git stash drop # Remove a stash
  5. git stash pop # Apply and remove the latest stash
  6. git stash branch <branch> # Create a new branch and apply a stash
  7. git stash save "<message>" # Save changes with a custom stash message
  8. git stash clear # Remove all stashed changes
  9. git stash apply <stash> # Apply a specific stash
  10. git stash drop <stash> # Remove a specific stash

All rights reserved

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí