All Git Commands

Comprehensive reference for every Git command from basic to advanced

All Git Commands

Comprehensive reference for every Git command from basic to advanced

A. Setup & Configuration

git config

Syntax

git config [--local|--global|--system] [<key> [<value>]]

Description

Get and set repository or global options. Configure Git behavior, preferences, and user information.

Examples

# Set global user name and email
git config --global user.name "John Doe"
git config --global user.email "john@example.com"

# View all global settings
git config --global --list

# Set local repository settings
git config user.name "Jane Smith"
git config user.email "jane@work.com"

# Set default editor
git config --global core.editor "code --wait"

VS Code Usage

In VS Code, you can configure Git settings through the Settings UI (Ctrl+,) or by editing the .git/config file directly. The Source Control panel will reflect your configuration changes immediately.

  • Open Settings (Ctrl+,) and search for "Git"
  • Modify settings like "Git: Auto Fetch" or "Git: Confirm Sync"
  • User settings are stored in ~/.gitconfig on macOS/Linux or %USERPROFILE%\.gitconfig on Windows

Tips & Best Practices

  • Always set your user.name and user.email globally for proper attribution
  • Use --global for settings that apply to all repositories
  • Use --local for repository-specific settings
  • Configure your preferred merge tool with merge.tool setting

git help

Syntax

git help [<command>|<guide>]

Description

Display help information about Git or a specific Git command. Provides manual pages and guides.

Examples

# Show general help
git help

# Show help for a specific command
git help commit

# Show a conceptual guide
git help tutorial

# Show all available guides
git help -g

VS Code Usage

In VS Code, you can access Git help through the integrated terminal or by using extensions like GitLens. Press Ctrl+` to open the terminal and use git help commands directly.

  • Use Ctrl+Shift+P and type "Git" to access Git commands palette
  • Install GitLens extension for enhanced Git help and visualization
  • Right-click on files in the Source Control panel for context-specific help

Tips & Best Practices

  • Use git help -a to see all available commands
  • Use git help -g to see all available guides
  • Use git help <command> for detailed information about any command
  • Access comprehensive documentation at https://git-scm.com/docs

B. Getting & Creating Projects

git init

Syntax

git init [<directory>]

Description

Create an empty Git repository or reinitialize an existing one. Initializes a .git directory with all necessary metadata.

Examples

# Initialize a new repository in current directory
git init

# Initialize a new repository in a specific directory
git init my-project

# Initialize with specific branch name (Git 2.28+)
git init -b main

VS Code Usage

In VS Code, you can initialize a Git repository through the Source Control panel. Click "Initialize Repository" when opening a folder that isn't already a Git repository.

  • Open a folder in VS Code
  • Click the Source Control icon in the Activity Bar
  • Click "Initialize Repository" if not already initialized
  • Use Ctrl+Shift+P and type "Git: Initialize Repository"

Tips & Best Practices

  • Always initialize a repository before starting work on a new project
  • Use -b main to set the default branch name to main instead of master
  • Consider adding a .gitignore file immediately after initialization
  • Initialize in an empty directory to avoid accidentally tracking unwanted files

git clone

Syntax

git clone [<options>] [--] <repository> [<directory>]

Description

Clone a repository into a new directory. Creates a local copy of a remote repository including all history and branches.

Examples

# Clone a repository into a new directory
git clone https://github.com/user/repo.git

# Clone into a specific directory
git clone https://github.com/user/repo.git my-local-folder

# Clone only the latest commit (shallow clone)
git clone --depth 1 https://github.com/user/repo.git

# Clone a specific branch
git clone -b branch-name https://github.com/user/repo.git

VS Code Usage

In VS Code, you can clone repositories through the Welcome screen or Command Palette. Use "Git: Clone" from the Command Palette (Ctrl+Shift+P) to clone a repository.

  • Press Ctrl+Shift+P and type "Git: Clone"
  • Enter the repository URL when prompted
  • Select the local directory for the clone
  • VS Code will automatically open the cloned repository

Tips & Best Practices

  • Use --depth 1 for faster clones when you don't need full history
  • Clone into a new directory to avoid conflicts with existing files
  • Use -b <branch> to clone a specific branch directly
  • SSH URLs (git@github.com:user/repo.git) are preferred for authenticated repositories

C. Basic Snapshotting

git add

Syntax

git add [--verbose | -v] [--dry-run | -n] [--force | -f] [--interactive | -i] [--patch | -p]
          [--edit | -e] [--all | -A] [--update | -u] [--renormalize]
          [--intent-to-add | -N] [--refresh] [--ignore-errors] [--ignore-missing]
          [--chmod=(+|-)x] [--] [<pathspec>...]

Description

Add file contents to the index (staging area). Prepares changes for the next commit.

Examples

# Add a specific file
git add README.md

# Add all files in current directory
git add .

# Add all files with changes (tracked files only)
git add -u

# Add all files including new, modified, and deleted
git add -A

# Add files interactively
git add -i

# Add parts of a file interactively
git add -p

VS Code Usage

In VS Code, you can add files to the staging area through the Source Control panel. Click the + icon next to changed files or use the "Stage All Changes" button.

  • View changed files in the Source Control panel
  • Click the + icon next to individual files to stage them
  • Click the + icon next to the "Changes" header to stage all files
  • Use the Command Palette (Ctrl+Shift+P) for "Git: Stage" commands

Tips & Best Practices

  • Stage files thoughtfully - only include related changes in each commit
  • Use git add -p to review and stage changes in hunks
  • Use .gitignore to exclude files you never want to track
  • Check git status frequently to see what's staged and what's not

git status

Syntax

git status [<options>] [--] [<pathspec>...]

Description

Show the working tree status. Displays paths that have differences between the index file and the current HEAD commit.

Examples

# Show status in long format
git status

# Show status in short format
git status -s

# Show status in branch format
git status -b

# Show status with ignored files
git status --ignored

VS Code Usage

In VS Code, the Source Control panel continuously shows the repository status. Changed files appear with colored badges indicating their status (M for modified, U for untracked, etc.).

  • The Source Control icon in the Activity Bar shows the number of changes
  • Files are grouped by status (Changes, Staged Changes, Untracked Files)
  • Click on files to see detailed diffs in the editor
  • Use Ctrl+Shift+G to quickly open the Source Control panel

Tips & Best Practices

  • Check git status frequently to understand the state of your repository
  • Use git status -s for a concise view of changes
  • Pay attention to the branch information at the top of the status output
  • Use git status --ignored to see files that are being ignored by .gitignore

Download the complete Git commands reference as a PDF for offline use.

Download PDF
  • Files are grouped by status (Changes, Staged Changes, Untracked Files)
  • Click on files to see detailed diffs in the editor
  • Use Ctrl+Shift+G to quickly open the Source Control panel
  • Tips & Best Practices

    git diff

    Syntax

    git diff [<options>] [<commit>] [--] [<path>...]
    git diff [<options>] --cached [<commit>] [--] [<path>...]
    git diff [<options>] <commit> <commit> [--] [<path>...]

    Description

    Show changes between commits, commit and working tree, etc. Displays differences in a format similar to diff(1).

    Examples

    # Show changes in working directory not yet staged
    git diff
    
    # Show changes that are staged for the next commit
    git diff --cached
    
    # Show changes between two commits
    git diff HEAD~2 HEAD
    
    # Show changes in a specific file
    git diff README.md
    
    # Show changes with word-level highlighting
    git diff --word-diff

    VS Code Usage

    In VS Code, you can view diffs directly in the editor. Click on a changed file in the Source Control panel to see a side-by-side diff view. The gutter shows colored bars indicating changes.

    • Click on changed files in the Source Control panel to see diffs
    • Use the split view to see "before" and "after" side-by-side
    • Inline diff view shows changes within lines
    • Use the Command Palette (Ctrl+Shift+P) for "Git: Diff" commands

    Tips & Best Practices

    • Use git diff to review changes before staging them
    • Use git diff --cached to review what will be committed
    • Use --word-diff for better visibility of small changes
    • Use external diff tools with git difftool for enhanced visualization

    git commit

    Syntax

    git commit [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
                 [--dry-run] [(-c | -C | --fixup | --squash) <commit>]
                 [-F <file> | -m <msg>] [--reset-author] [--allow-empty]
                 [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
                 [--date=<date>] [--cleanup=<mode>] [--[no-]status]
                 [-i | -o] [-S[<keyid>]] [--help] [--] [<file>...]

    Description

    Record changes to the repository. Stores the current contents of the index in a new commit along with a log message.

    Examples

    # Commit staged changes with a message
    git commit -m "Add new feature"
    
    # Commit all tracked files (skip staging)
    git commit -am "Fix bug in user authentication"
    
    # Amend the last commit
    git commit --amend -m "Updated commit message"
    
    # Commit with a detailed message from file
    git commit -F commit-message.txt
    
    # Commit and sign with GPG
    git commit -S -m "Signed commit"

    VS Code Usage

    In VS Code, you can commit changes through the Source Control panel. Enter a commit message in the text box and click the checkmark icon or press Ctrl+Enter.

    • Enter commit message in the text box at the top of Source Control panel
    • Click the checkmark icon or press Ctrl+Enter to commit
    • Use the Command Palette (Ctrl+Shift+P) for "Git: Commit" commands
    • Enable "Git: Auto Fetch" to keep up with remote changes

    Tips & Best Practices

    • Write clear, concise commit messages in imperative mood
    • Keep commits focused on a single logical change
    • Use git commit -v to see the diff while writing commit message
    • Use --amend to fix mistakes in the last commit

    git reset

    Syntax

    git reset [-q] [<tree-ish>] [--] <paths>...
    git reset (--patch | -p) [<tree-ish>] [--] [<paths>...]
    git reset [--soft | --mixed | --hard | --merge | --keep] [-q] [<commit>]

    Description

    Reset current HEAD to the specified state. Can be used to undo changes at different levels (working directory, staging area, commits).

    Examples

    # Unstage a file (equivalent to git reset HEAD <file>)
    git reset README.md
    
    # Undo last commit but keep changes staged
    git reset --soft HEAD~1
    
    # Undo last commit and unstage changes
    git reset --mixed HEAD~1
    
    # Undo last commit and discard all changes
    git reset --hard HEAD~1
    
    # Reset to a specific commit
    git reset --hard abc1234

    VS Code Usage

    In VS Code, you can reset changes through the Source Control panel context menu. Right-click on files to unstage them or use the Command Palette for reset commands.

    • Right-click on staged files and select "Unstage Changes"
    • Use the Command Palette (Ctrl+Shift+P) for "Git: Undo Last Commit"
    • View commit history in the Git view to reset to specific commits
    • Use "Git: Reset" commands to reset to specific states

    Tips & Best Practices

    • Use --soft to undo commits while preserving changes
    • Use --mixed (default) to unstage changes but keep them in working directory
    • Use --hard with extreme caution as it permanently deletes changes
    • Always ensure you have backups before using --hard reset

    git rm

    Syntax

    git rm [-f] [-n] [--cached] [--ignore-unmatch] [--quiet] [--] <file>...

    Description

    Remove files from the working tree and from the index. Stops tracking files and optionally deletes them from the filesystem.

    Examples

    # Remove a file from both working directory and index
    git rm README.txt
    
    # Remove a file from index but keep it in working directory
    git rm --cached README.txt
    
    # Remove files matching a pattern
    git rm *.log
    
    # Force removal of files with staged changes
    git rm -f important-file.txt

    VS Code Usage

    In VS Code, you can remove files through the Explorer panel or Source Control panel. Right-click on files and select "Delete" to remove them from both filesystem and Git tracking.

    • Right-click on files in Explorer and select "Delete"
    • Deleted files appear in the Source Control panel as "Deleted"
    • Stage the deletion by clicking the + icon next to deleted files
    • Use the Command Palette (Ctrl+Shift+P) for "Git: Delete" commands

    Tips & Best Practices

    • Use --cached to stop tracking files without deleting them from disk
    • Use -f to force removal of files with uncommitted changes
    • Always commit after using git rm to record the deletion
    • Use .gitignore for files you want to ignore rather than removing them

    git mv

    Syntax

    git mv [<options>] <source> <destination>

    Description

    Move or rename a file, directory, or symlink. Equivalent to doing a git rm followed by a git add.

    Examples

    # Rename a file
    git mv old-name.txt new-name.txt
    
    # Move a file to a different directory
    git mv file.txt directory/
    
    # Rename a directory
    git mv old-directory/ new-directory/

    VS Code Usage

    In VS Code, you can rename or move files through the Explorer panel. Right-click on files or directories and select "Rename" to change their names while preserving Git history.

    • Right-click on files in Explorer and select "Rename"
    • Git automatically detects the rename operation
    • Renamed files appear in the Source Control panel with rename indicators
    • Use the Command Palette (Ctrl+Shift+P) for file management commands

    Tips & Best Practices

    • Git automatically detects renames when you use git mv
    • Use git mv instead of separate rm and add operations
    • Commit after renaming to preserve history
    • Git tracks file content, so history is preserved even after renames

    D. Branching & Merging

    git branch

    Syntax

    git branch [<options>] [<branchname> [<start-point>]]

    Description

    List, create, or delete branches. Branches are lightweight pointers to commits that allow for divergent development paths.

    Examples

    # List all branches
    git branch
    
    # Create a new branch
    git branch feature/new-ui
    
    # Create a branch starting from a specific commit
    git branch bugfix/issue-123 abc1234
    
    # Delete a branch
    git branch -d feature/new-ui
    
    # Force delete a branch
    git branch -D feature/new-ui
    
    # Rename current branch
    git branch -m new-branch-name

    VS Code Usage

    In VS Code, you can manage branches through the Status Bar or Command Palette. Click on the branch name in the Status Bar to switch branches or create new ones.

    • Click on the branch name in the Status Bar to view and switch branches
    • Use the Command Palette (Ctrl+Shift+P) for "Git: Create Branch" commands
    • View branch history and manage branches in the Git view
    • Use the Branches view in Source Control to see all remote and local branches

    Tips & Best Practices

    • Use descriptive branch names that indicate the purpose (e.g., feature/user-authentication)
    • Delete branches after merging to keep the repository clean
    • Use git branch -a to see both local and remote branches
    • Regularly prune deleted remote branches with git fetch --prune

    git checkout

    Syntax

    git checkout [<options>] <branch>
    git checkout [<options>] [<branch>] -- <file>...
    git checkout [<options>] <commit> -- <file>...
    git checkout [<options>] -- <file>...

    Description

    Switch branches or restore working tree files. Updates files in the working tree to match the version in the index or the specified tree.

    Examples

    # Switch to an existing branch
    git checkout feature/new-ui
    
    # Create and switch to a new branch
    git checkout -b feature/user-authentication
    
    # Restore a file to its state in HEAD
    git checkout -- README.md
    
    # Restore a file to its state in a specific commit
    git checkout abc1234 -- README.md
    
    # Detach HEAD at a specific commit
    git checkout abc1234

    VS Code Usage

    In VS Code, you can switch branches by clicking on the branch name in the Status Bar. Use the Command Palette for more advanced checkout operations.

    • Click on the branch name in the Status Bar to switch branches
    • Use the Command Palette (Ctrl+Shift+P) for "Git: Checkout to" commands
    • View commit history and checkout to specific commits in the Git view
    • Restore files by right-clicking on them in Source Control and selecting "Discard Changes"

    Tips & Best Practices

    • Use git switch instead of git checkout for branch switching (Git 2.23+)
    • Use git restore instead of git checkout for file restoration (Git 2.23+)
    • Always commit or stash changes before switching branches
    • Use -b flag to create and switch to a new branch in one command

    git switch

    Syntax

    git switch [<options>] [--no-guess] <branch>
    git switch [<options>] --detach [<start-point>]
    git switch [<options>] (-c|-C) <new-branch> [<start-point>]

    Description

    Switch to a branch. A more focused alternative to git checkout for branch switching operations (introduced in Git 2.23).

    Examples

    # Switch to an existing branch
    git switch feature/new-ui
    
    # Create and switch to a new branch
    git switch -c feature/user-authentication
    
    # Switch to a branch that might exist remotely
    git switch feature/remote-branch
    
    # Switch to a commit in detached HEAD state
    git switch --detach abc1234

    VS Code Usage

    In VS Code, git switch functionality is available through the same branch switching interface. Click on the branch name in the Status Bar or use the Command Palette.

    • Click on the branch name in the Status Bar to switch branches
    • Use the Command Palette (Ctrl+Shift+P) for "Git: Switch Branch" commands
    • VS Code internally uses git switch when available for branch operations
    • Create new branches through the branch switching interface

    Tips & Best Practices

    • Use git switch instead of git checkout for cleaner branch operations
    • git switch is more intuitive and less error-prone than git checkout
    • Use -c flag to create and switch to a new branch
    • Use --detach to explicitly enter detached HEAD state

    git merge

    Syntax

    git merge [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
                [-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
                [--[no-]rerere-autoupdate] [-m <msg>] [-F <file>] [<commit>...]

    Description

    Join two or more development histories together. Incorporates changes from the named commits into the current branch.

    Examples

    # Merge a branch into current branch
    git merge feature/new-ui
    
    # Squash all commits from a branch into one
    git merge --squash feature/new-ui
    
    # Perform a merge but don't commit automatically
    git merge --no-commit feature/new-ui
    
    # Abort a merge in progress
    git merge --abort

    VS Code Usage

    In VS Code, you can merge branches through the Command Palette or Git view. Use the integrated merge conflict resolution tools when conflicts occur.

    • Use the Command Palette (Ctrl+Shift+P) for "Git: Merge" commands
    • View and manage merge operations in the Git view
    • VS Code provides visual merge conflict resolution tools
    • Use the Source Control panel to resolve conflicts with inline tools

    Tips & Best Practices

    • Always pull the latest changes before merging to reduce conflicts
    • Use --squash for feature branches to create a single commit
    • Use --no-ff to preserve branch structure in history
    • Test thoroughly after merging to ensure no regressions

    git mergetool

    Syntax

    git mergetool [--tool=<tool>] [-y | --[no-]prompt] [<file>...]

    Description

    Run merge conflict resolution tools to resolve merge conflicts. Opens external tools to help resolve conflicts in files.

    Examples

    # Run the default merge tool
    git mergetool
    
    # Run a specific merge tool
    git mergetool --tool=vimdiff
    
    # Run merge tool for specific files
    git mergetool conflicted-file.txt
    
    # Skip the prompt for each file
    git mergetool -y

    VS Code Usage

    In VS Code, merge conflicts are resolved through the integrated merge editor. When conflicts occur, VS Code automatically highlights them and provides inline resolution tools.

    • VS Code automatically detects merge conflicts and highlights them
    • Use the inline conflict resolution buttons (Accept Current, Accept Incoming, etc.)
    • Open the merge editor with "Git: Open Merge Editor" from Command Palette
    • Use the Source Control panel to navigate between conflicts

    Tips & Best Practices

    • Configure your preferred merge tool with git config --global merge.tool
    • Use git mergetool --tool-help to see available tools
    • Test the resolved files after using the merge tool
    • Always commit after resolving conflicts

    git log

    Syntax

    git log [<options>] [<revision-range>] [[--] <path>...]

    Description

    Show commit logs. Display commit history with various formatting options, especially useful for understanding branch history.

    Examples

    # Show log with branch graph
    git log --graph --oneline --all
    
    # Show commits for a specific branch
    git log feature/new-ui
    
    # Show commits that are in one branch but not another
    git log main..feature/new-ui
    
    # Show commits that are in either branch but not both
    git log main...feature/new-ui

    VS Code Usage

    In VS Code, you can view commit history through the Git view. Click on commits to see detailed information and use the integrated graph view for branch visualization.

    • View commit history in the Git view by clicking on the branch history icon
    • Click on commits to see detailed information and file changes
    • Use GitLens extension for enhanced log visualization and graph views
    • Search and filter commits through the Git view interface

    Tips & Best Practices

    • Use --graph --oneline --all for a visual representation of branch history
    • Use git log <branch1>..<branch2> to see what commits are in branch2 but not branch1
    • Use git log --since and --until to filter by date
    • Use git log --grep to search commit messages

    E. Sharing & Updating

    git fetch

    Syntax

    git fetch [<options>] [<repository> [<refspec>...]]
    git fetch [<options>] <group>
    git fetch --multiple [<options>] [(git fetch-pack|<repository> [<refspec>...])...]
    git fetch --all [<options>]

    Description

    Download objects and refs from another repository. Fetches changes from remote repositories without merging them.

    Examples

    # Fetch all changes from the default remote
    git fetch
    
    # Fetch changes from a specific remote
    git fetch origin
    
    # Fetch all remotes
    git fetch --all
    
    # Fetch and prune deleted remote branches
    git fetch --prune
    
    # Fetch a specific branch
    git fetch origin feature/new-ui

    VS Code Usage

    In VS Code, you can fetch changes through the Source Control panel or Command Palette. Enable "Git: Auto Fetch" to automatically fetch changes periodically.

    • Use the Command Palette (Ctrl+Shift+P) for "Git: Fetch" commands
    • Enable "Git: Auto Fetch" in Settings to fetch automatically
    • View remote changes in the Git view before merging
    • Use the sync button in the Status Bar to fetch and merge in one operation

    Tips & Best Practices

    • Use git fetch regularly to stay informed of remote changes
    • Use --prune to clean up deleted remote branches locally
    • Always fetch before merging to see what changes you're incorporating
    • Use git fetch --all to update from all remotes

    git pull

    Syntax

    git pull [<options>] [<repository> [<refspec>...]]

    Description

    Fetch from and integrate with another repository or a local branch. Combines git fetch and git merge in one command.

    Examples

    # Pull changes from the default remote branch
    git pull
    
    # Pull and rebase instead of merging
    git pull --rebase
    
    # Pull from a specific remote and branch
    git pull origin feature/new-ui
    
    # Pull and automatically stash local changes
    git pull --autostash

    VS Code Usage

    In VS Code, you can pull changes by clicking the sync button in the Status Bar or using the Command Palette. The sync button combines fetch and merge operations.

    • Click the sync button (⇄) in the Status Bar to pull and push changes
    • Use the Command Palette (Ctrl+Shift+P) for "Git: Pull" commands
    • Enable "Git: Auto Fetch" to stay updated with remote changes
    • VS Code will warn about conflicts before pulling if there are local changes

    Tips & Best Practices

    • Use --rebase to maintain a linear history
    • Commit or stash local changes before pulling to avoid conflicts
    • Use --autostash with --rebase to automatically stash and restore local changes
    • Always review changes after pulling to ensure integration is correct

    git push

    Syntax

    git push [<options>] [<repository> [<refspec>...]]

    Description

    Update remote refs along with associated objects. Uploads local commits to a remote repository.

    Examples

    # Push current branch to default remote
    git push
    
    # Push to a specific remote and branch
    git push origin feature/new-ui
    
    # Push all branches
    git push --all
    
    # Push tags
    git push --tags
    
    # Set upstream branch and push
    git push -u origin feature/new-ui
    
    # Force push (use with caution)
    git push --force-with-lease

    VS Code Usage

    In VS Code, you can push changes by clicking the sync button in the Status Bar or using the Command Palette. The sync button combines fetch and push operations.

    • Click the sync button (⇄) in the Status Bar to push and pull changes
    • Use the Command Palette (Ctrl+Shift+P) for "Git: Push" commands
    • View push status and progress in the Status Bar
    • VS Code will show error messages if push fails due to conflicts

    Tips & Best Practices

    • Use -u to set the upstream branch for future push/pull operations
    • Use --force-with-lease instead of --force for safer force pushes
    • Always pull before pushing to avoid conflicts
    • Use git push --tags to share annotated tags with the remote

    git remote

    Syntax

    git remote [-v | --verbose] show [-n] <name>...
    git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=<fetch|push>] <name> <url>
    git remote rename <old> <new>
    git remote remove <name>
    git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
    git remote set-branches [--add] <name> <branch>...
    git remote get-url [--push] [--all] <name>
    git remote set-url [--push] <name> <newurl> [<oldurl>]
    git remote set-url --add [--push] <name> <newurl>
    git remote set-url --delete [--push] <name> <url>
    git remote [-v | --verbose] show [-n] <name>...

    Description

    Manage set of tracked repositories. Manage connections to other repositories for sharing and collaboration.

    Examples

    # List all remotes
    git remote -v
    
    # Add a new remote
    git remote add origin https://github.com/user/repo.git
    
    # Rename a remote
    git remote rename origin upstream
    
    # Remove a remote
    git remote remove upstream
    
    # Show information about a remote
    git remote show origin
    
    # Update URL for a remote
    git remote set-url origin git@github.com:user/repo.git

    VS Code Usage

    In VS Code, you can manage remotes through the Command Palette or Git view. Remotes are automatically configured when cloning repositories.

    • View remotes in the Git view under the "Remotes" section
    • Use the Command Palette (Ctrl+Shift+P) for "Git: Add Remote" commands
    • VS Code automatically configures remotes when cloning repositories
    • View remote URLs and branch tracking information in the Git view

    Tips & Best Practices

    • Use SSH URLs instead of HTTPS for easier authentication
    • Regularly prune deleted remote branches with git fetch --prune
    • Use multiple remotes for complex workflows (e.g., upstream for original repository)
    • Always verify remote URLs with git remote -v

    F. Inspection & Comparison

    git log

    Syntax

    git log [<options>] [<revision-range>] [[--] <path>...]

    Description

    Show commit logs. Display commit history with various formatting options.

    Examples

    # Show log with basic information
    git log
    
    # Show log in one line per commit
    git log --oneline
    
    # Show log with diff for each commit
    git log -p
    
    # Show log for last 3 commits
    git log -3
    
    # Show log with statistics
    git log --stat
    
    # Show log with specific format
    git log --format=fuller

    VS Code Usage

    In VS Code, you can view commit history through the Git view. Click on commits to see detailed information and use the integrated graph view for visualization.

    • View commit history in the Git view by clicking on the branch history icon
    • Click on commits to see detailed information and file changes
    • Use GitLens extension for enhanced log visualization and search
    • Search and filter commits through the Git view interface

    Tips & Best Practices

    • Use --oneline for a concise view of commit history
    • Use --since and --until to filter by date
    • Use --grep to search commit messages
    • Use --author to filter by commit author

    git diff

    Syntax

    git diff [<options>] [<commit>] [--] [<path>...]

    Description

    Show changes between commits, commit and working tree, etc. Compare different versions of files and commits.

    Examples

    # Show differences between working directory and index
    git diff
    
    # Show differences between index and last commit
    git diff --cached
    
    # Show differences between two commits
    git diff HEAD~3 HEAD
    
    # Show differences for a specific file
    git diff README.md
    
    # Show differences with color highlighting
    git diff --color

    VS Code Usage

    In VS Code, you can view diffs directly in the editor. Click on a changed file in the Source Control panel to see a side-by-side diff view.

    • Click on changed files in the Source Control panel to see diffs