This document provides solutions to common Git issues encountered during development.
You have uncommitted changes on your current branch but need to create a new branch from origin/development (or any other remote branch).
# You're on branch 03-user-crud with uncommitted changes
git status
# Shows modified files that aren't committed yet
# Trying to checkout a new branch fails or brings unwanted changesgit stash push -m "WIP: Description of your work"This saves your uncommitted changes temporarily.
git fetch originThis ensures you have the latest remote branch information.
git checkout -b 04-testing origin/developmentThis creates and switches to a new branch based on the remote branch.
git push -u origin 04-testingThis pushes the new branch and sets up tracking.
# View stashed changes
git stash list
# View what's in a specific stash
git stash show -p stash@{0}
# Apply stash to current branch (keeps stash)
git stash apply stash@{0}
# Apply stash and remove it from stash list
git stash pop stash@{0}
# Go back to original branch and restore changes
git checkout 03-user-crud
git stash pop # Applies the most recent stash$ git stash push -m "WIP: Testing setup and CRUD implementation"
Saved working directory and index state On 03-user-crud: WIP: Testing setup and CRUD implementation
$ git checkout -b 04-testing origin/development
branch '04-testing' set up to track 'origin/development'.
Switched to a new branch '04-testing'
$ git push -u origin 04-testing
* [new branch] 04-testing -> 04-testing
branch '04-testing' set up to track 'origin/04-testing'.npm scripts using Unix-style environment variables don't work on Windows PowerShell.
> NODE_OPTIONS=--experimental-vm-modules jest
'NODE_OPTIONS' is not recognized as an internal or external command# Install cross-env
npm install --save-dev cross-env
# Update package.json script
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest"git branch -agit branch -vv# Delete local branch (safe - only if merged)
git branch -d branch-name
# Force delete local branch
git branch -D branch-name
# Delete remote branch
git push origin --delete branch-name# Fetch all remote changes
git fetch origin
# Pull changes from tracked branch
git pull
# Rebase current branch on remote
git pull --rebase origin branch-name# After a merge conflict
git status # Shows conflicted files
# Edit conflicted files manually, then:
git add .
git commit -m "Resolve merge conflicts"git merge --abortgit reset HEAD file-name# Single file
git checkout -- file-name
# All unstaged changes
git checkout .# Soft reset (keeps changes staged)
git reset --soft HEAD~1
# Mixed reset (keeps changes unstaged)
git reset HEAD~1
# Hard reset (discards all changes)
git reset --hard HEAD~1git remote add origin https://github.com/username/repo.gitgit remote set-url origin https://github.com/username/new-repo.gitgit remote -v# Stash with message
git stash push -m "Work in progress"
# Stash specific files
git stash push -m "Message" file1.js file2.js
# List all stashes
git stash list
# Show stash contents
git stash show -p stash@{0}
# Apply specific stash
git stash apply stash@{1}
# Drop a stash
git stash drop stash@{0}
# Clear all stashes
git stash clearGit warnings about CRLF/LF line endings on Windows.
Configure Git to handle line endings automatically:
# For the current repository
git config core.autocrlf true
# Globally
git config --global core.autocrlf truegit status # Current status
git log --oneline # Commit history
git log --graph --oneline # Visual commit historygit branch # List local branches
git branch -r # List remote branches
git branch -a # List all branches
git checkout branch-name # Switch branch
git checkout -b new-branch # Create and switchgit fetch origin # Fetch remote changes
git pull # Fetch and merge
git push # Push to remote
git push -u origin branch # Push and set upstream- Always check
git statusfirst to understand your current state - Use
git log --onelineto see recent commits before making changes - Fetch before creating new branches to ensure you have latest remote info
- Use descriptive stash messages to remember what you stashed
- Test commands with
--dry-runwhen available to see what would happen