Git Commands
General workflow
Section titled “General workflow”-
Clone the repository:
Terminal window git clone <repoUrl> -
Check out an existing branch or create a new one:
Terminal window git checkout <branchName># or create a new branchgit checkout -b <newBranchName> -
Check your current branch and staged changes:
Terminal window git status -
Stage your changes:
Terminal window git add --all# or stage a specific filegit add <filePath> -
Commit staged changes:
Terminal window git commit -m "commit message" -
Push to remote:
Terminal window # First push on a new branchgit push -u origin <branchName># Subsequent pushesgit push
Other useful commands
Section titled “Other useful commands”Syncing
Section titled “Syncing”git pull— pull latest changes from remote into your local branchgit fetch— fetch remote changes without merging them into your local environment
Merging & rebasing
Section titled “Merging & rebasing”git merge <branchName>— merge another branch into your current branchgit rebase <branchName>— rebase your current branch on top of another branch
Branch management
Section titled “Branch management”git branch -d <branchName>— delete a local branchgit push origin --delete <branchName>— delete a remote branch
Undoing changes
Section titled “Undoing changes”git reset --hard— discard all uncommitted changes
External resources
Section titled “External resources” Git Cheat Sheet Official quick reference for the most common Git commands.