Git is a version control system that tracks changes in your codebase. You can edit README.md using Markdown or HTML.
# Check Git version
git --version
# Configure Git globally
git config --global user.name "My Name"
git config --global user.email "someone@email.com"
# Check current Git configuration
git config --list
# Start a Git repository
git init
# Clone a repository
git clone "repo-link"
# Link/unlink remote repository
git remote add origin "link"
git remote remove origin
git remote -v # Verify remote repo
# Initializing a new project (Quick Guide)
echo "# learning-Git" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/ssrthakkumar/learning-Git.git
git push -u origin main # -u sets upstream
# Link an existing local folder to GitHub repo
git remote add origin https://github.com/ssrthakkumar/learning-Git.git
git branch -M main
git push -u origin main
# Track & commit changes
git status # Show status of working directory
git add filename # Stage a single file
git add . # Stage all files
git commit -m "message" # Commit with message
# Push & pull changes
git push origin main # Push to main branch
git pull origin main # Pull from remote main branch
# Branching
git branch # List branches
git branch -M main # Rename current branch to main
git checkout -b new # Create and switch to new branch
git checkout branch # Switch to a branch
git branch -d branch # Delete a branch
git push origin branch # Push a branch to remote
git diff branch # Compare with another branch
git merge branch # Merge a branch into current one
# Merge Conflicts
# Happens when multiple branches edit the same part of a file.
# Git will prompt you to resolve it manually.
# Undoing Changes
# Reset staged files
git reset filename # Unstage a specific file
git reset # Unstage all files
# Undo commits
git reset HEAD~1 # Undo last commit but keep changes
git reset <commit-hash> # Reset to specific commit
git reset --hard <commit-hash> # Reset and remove all changes after that
# File & directory operations
ls # List files (linux or git bash on windows)
ls -a # List all files including hidden (linux or git bash on windows)
dir # list files and folders (windows and in vs code terminal)
dir /a # include hidden files (windows and in vs code terminal)
cd folder-name # Move to a folder
cd .. # Go back one directory
cd / # Root directory
mkdir folder-name # Create a directory (folder)
' ' > filename # Creates a file
mkdir -p a/b/c # Create nested directories
Remove-Item fileName # Remove a file
Remove-Item folderName -Recurse -Force #Removes a file or a directory
Remove-Item * -Recurse -Force #Removes all files and directories(folders) from inside a directory(folder)
# NOTE - We can use rm in place or Remove-Item as an abbreviation