Skip to main content

Git Commands Reference

Complete Git command reference with VS Code equivalents.


Configuration Commands

Set Your Identity

# Set your name (use your real name)
git config --global user.name "John Smith"

# Set your email (use same email as GitHub account)
git config --global user.email "john.smith@company.com"

# Verify your settings
git config --global --list

Clone Repository

VS Code (Visual)Git Command (Terminal)
1. Press Ctrl+Shift+Pcd C:\Projects
2. Type 'Git: Clone'git clone https://github.com/[org]/repo.git
3. Paste repository URLcd repo-name
4. Choose folder location
5. Click 'Open' when done

Branch Commands

CommandWhat It Does
git branchList all local branches (* = current)
git branch -aList all branches (local + remote)
git checkout [branch]Switch to existing branch
git checkout -b [branch]Create AND switch to new branch
git branch -d [branch]Delete local branch (safe)
git branch -D [branch]Delete local branch (force)

VS Code Equivalent

  • Click branch name in bottom-left
  • Select branch to switch, or "+ Create new branch..."

Staging & Commit Commands

CommandWhat It Does
git statusShow changed/staged files
git add [file]Stage specific file
git add .Stage ALL changed files
git commit -m "message"Commit staged files with message
git commit -am "message"Stage + commit all tracked files
git diffShow unstaged changes
git diff --stagedShow staged changes

VS Code Equivalent

  1. Open Source Control panel (Ctrl+Shift+G)
  2. Click + to stage files
  3. Type message in text box
  4. Click ✓ to commit

Remote Commands (Push/Pull)

CommandWhat It Does
git fetchDownload remote changes (don't merge)
git pullDownload AND merge remote changes
git pushUpload commits to remote
git push -u origin [branch]Push new branch to remote first time
git push origin --delete [branch]Delete remote branch

VS Code Equivalent

  • Click Sync button (↑↓) in status bar
  • Or Source Control → ... → Pull/Push

Merge Commands

CommandWhat It Does
git merge [branch]Merge branch into current branch
git merge --abortCancel merge (if conflicts)
git rebase [branch]Reapply commits on top of branch

Complete Workflow Examples

New Feature Workflow

# 1. Get latest develop
git checkout develop
git pull origin develop

# 2. Create feature branch
git checkout -b feature/vendor-NS123-invoice-automation

# 3. Make your changes, then stage and commit
git add .
git commit -m "[NS-123] Add invoice validation"

# 4. Push to GitHub
git push -u origin feature/vendor-NS123-invoice-automation

# 5. Go to GitHub.com and create Pull Request

# 6. After PR merged, cleanup
git checkout develop
git pull origin develop
git branch -d feature/vendor-NS123-invoice-automation

Bug Fix Workflow

# 1. Get latest develop
git checkout develop
git pull origin develop

# 2. Create bugfix branch
git checkout -b bugfix/it-NS456-fix-tax-calculation

# 3. Make your changes, then stage and commit
git add .
git commit -m "[NS-456] Fix tax calculation for EU customers"

# 4. Push to GitHub
git push -u origin bugfix/it-NS456-fix-tax-calculation

# 5. Go to GitHub.com and create Pull Request to develop

# 6. After PR merged, cleanup
git checkout develop
git pull origin develop
git branch -d bugfix/it-NS456-fix-tax-calculation

Emergency Hotfix Workflow

Important

Hotfixes bypass develop and go directly to main. NOTIFY IT LEAD FIRST!

# 1. Start from main (production)
git checkout main
git pull origin main

# 2. Create hotfix branch from main
git checkout -b hotfix/NS999-critical-payment-fix

# 3. Make emergency fix, test thoroughly
git add .
git commit -m "[NS-999] HOTFIX: Fix payment processing error"

# 4. Push hotfix branch
git push -u origin hotfix/NS999-critical-payment-fix

# 5. Create Pull Request to MAIN (not develop!)
# Go to GitHub.com → Create PR → Base: main

# 6. After PR merged to main, sync to develop
git checkout develop
git pull origin develop
git merge main
git push origin develop

# 7. Cleanup
git branch -d hotfix/NS999-critical-payment-fix

Keep Your Branch Updated

Method 1: Merge develop into your branch

# Make sure you're on your feature branch
git checkout feature/vendor-NS123-my-feature

# Get latest develop
git fetch origin

# Merge develop into your branch
git merge origin/develop

# If conflicts occur, resolve them, then:
git add .
git commit -m "Merge develop into feature branch"

# Push updated branch
git push

Method 2: Rebase (cleaner history)

# Make sure you're on your feature branch
git checkout feature/vendor-NS123-my-feature

# Get latest develop
git fetch origin

# Rebase your changes on top of develop
git rebase origin/develop

# If conflicts occur, resolve them, then:
git add .
git rebase --continue

# Force push (required after rebase)
git push --force-with-lease
warning

Only use rebase on branches that ONLY YOU are working on. Never rebase shared branches.


Resolving Merge Conflicts

What Conflicts Look Like

<<<<<<< HEAD
// Your version
var taxRate = 0.08;
var currency = "USD";
=======
// Their version
var taxRate = 0.10;
var currency = "EUR";
>>>>>>> origin/develop

Resolving via Git Commands

# 1. When you see "CONFLICT" message after merge/pull:
git status # Shows which files have conflicts

# 2. Open each conflicted file and edit manually:
# - Remove the <<<<<<, ======, >>>>>> markers
# - Keep the code you want (yours, theirs, or combination)
# - Save the file

# 3. Stage resolved files
git add [resolved-file]
# or stage all
git add .

# 4. Complete the merge
git commit -m "Resolve merge conflicts"

# 5. Push
git push

Cancel a Merge (Start Over)

# If you want to abort and try again
git merge --abort

# Or if during rebase
git rebase --abort

Undo Mistakes

Discard Uncommitted Changes

# Discard changes in specific file (CANNOT UNDO!)
git checkout -- [filename]

# Discard ALL uncommitted changes (DANGEROUS!)
git checkout -- .

# Or using newer syntax
git restore [filename]
git restore .

Unstage Files (Keep Changes)

# Unstage specific file (keep the changes)
git reset HEAD [filename]

# Unstage all files (keep the changes)
git reset HEAD

# Or using newer syntax
git restore --staged [filename]

Undo Last Commit (Keep Changes)

# Undo last commit but keep changes staged
git reset --soft HEAD~1

# Undo last commit and unstage changes
git reset HEAD~1

# Undo last commit and DISCARD changes (DANGEROUS!)
git reset --hard HEAD~1

Revert a Pushed Commit

# Create a new commit that undoes a previous commit
# (Safe - doesn't change history)
git revert [commit-hash]

# Find commit hash with
git log --oneline

Fix Commit Message

# Change last commit message (before push)
git commit --amend -m "New corrected message"

# If already pushed, need force push (careful!)
git push --force-with-lease

Temporarily Save Work (Stash)

Stash Your Changes

# Save current changes to stash
git stash

# Save with a description
git stash save "WIP: Working on invoice feature"

# Stash including untracked files
git stash -u

View & Restore Stashes

# List all stashes
git stash list

# Apply most recent stash (keep in stash list)
git stash apply

# Apply and remove from stash list
git stash pop

# Apply specific stash
git stash apply stash@{1}

# Delete a stash
git stash drop stash@{0}

# Clear all stashes
git stash clear
VS Code (Visual)Git Command
Source Control → ... → Stash → Stashgit stash
Source Control → ... → Stash → Apply Stashgit stash apply
Source Control → ... → Stash → Pop Stashgit stash pop

View History & Logs

# View commit history
git log

# Compact one-line format
git log --oneline

# Show last 5 commits
git log -5

# Show commits with file changes
git log --stat

# Show commits by author
git log --author="John"

# Show commits in date range
git log --since="2024-01-01" --until="2024-01-31"

# Graphical branch history
git log --oneline --graph --all

# See who changed each line of a file
git blame [filename]

# Show changes in a specific commit
git show [commit-hash]

Quick Reference Card

Daily Start Workflow

# Start of day - get latest code
git checkout develop
git pull origin develop

New Feature/Bug Workflow

git checkout develop
git pull origin develop
git checkout -b feature/vendor-NS123-description
# ... make changes ...
git add .
git commit -m "[NS-123] Description of changes"
git push -u origin feature/vendor-NS123-description
# Create PR on GitHub

Quick Save & Continue Later

# Save work without committing
git stash save "WIP: description"

# Later, restore work
git stash pop

Check What's Happening

git status          # What files changed?
git branch # What branch am I on?
git log --oneline # Recent commits
git diff # What did I change?

"Oh No" Commands

# I want to undo my changes to a file
git checkout -- [filename]

# I staged files by mistake
git reset HEAD [filename]

# I committed but want to undo (keep changes)
git reset --soft HEAD~1

# I need to abort a merge gone wrong
git merge --abort

VS Code Keyboard Shortcuts

Git Operations

ActionShortcut
Open Source Control PanelCtrl+Shift+G
Stage Selected ChangesCtrl+Enter (in Source Control)
Open Command PaletteCtrl+Shift+P
Quick Open FileCtrl+P

General Editing

ActionShortcut
Save FileCtrl+S
Save All FilesCtrl+K S
Open TerminalCtrl+`
File ExplorerCtrl+Shift+E
Search in FilesCtrl+Shift+F
Toggle SidebarCtrl+B
Split EditorCtrl+\

SuiteCloud Commands (Command Palette)

Access these by pressing Ctrl+Shift+P and typing the command:

ActionCommand
Deploy ProjectSuiteCloud: Deploy Project
Validate ProjectSuiteCloud: Validate Project
Import FilesSuiteCloud: Import Files
Import ObjectsSuiteCloud: Import Objects
Set Up AccountSuiteCloud: Set Up Account
List ObjectsSuiteCloud: List Objects

Right-Click Context Menu (SuiteCloud)

Right-click on a file in VS Code Explorer:

OptionDescription
Deploy to AccountDeploy single file to NetSuite
Compare with AccountCompare local vs NetSuite version
Upload File to AccountUpload without full project deploy

Golden Rules

  1. NEVER push directly to main or develop
  2. ALWAYS pull before starting new work
  3. ALWAYS create a branch for your changes
  4. Commit often with meaningful messages
  5. Push your branch daily (backup!)
  6. When in doubt, ASK before acting!