# Clone from GitHubgit clone https://github.com/username/repo.git# Clone with a different namegit clone https://github.com/username/repo.git my-folder# Clone a specific branchgit clone -b develop https://github.com/username/repo.git
Prepare changes for commit. This is Git’s “shopping cart.”
Copy
# Stage a single filegit add README.md# Stage all changesgit add .# Stage specific filesgit add file1.txt file2.txt# Stage all .js filesgit add *.js# Interactive staginggit add -p # Choose which changes to stage
Why a staging area? It lets you craft precise commits. You can modify 10 files but commit only 3 related changes.
# See what's changedgit status# Short formatgit status -s
Output explained:
Copy
On branch mainChanges to be committed: (use "git restore --staged <file>..." to unstage) modified: index.htmlChanges not staged for commit: (use "git add <file>..." to update what will be committed) modified: style.cssUntracked files: (use "git add <file>..." to include in what will be committed) script.js
# View commit historygit log# One line per commitgit log --oneline# With graphgit log --oneline --graph --all# Last 5 commitsgit log -5# Commits by authorgit log --author="John"# Commits in date rangegit log --since="2 weeks ago"# Show changes in each commitgit log -p
# Changes in working directory (not staged)git diff# Changes in staging areagit diff --staged# Changes between commitsgit diff abc123 def456# Changes in a specific filegit diff README.md# Word-level diffgit diff --word-diff
# Fix the last commit messagegit commit --amend -m "New message"# Add forgotten files to last commitgit add forgotten-file.txtgit commit --amend --no-edit
# Start your daygit status # See where you left offgit pull origin main # Get latest changes# Work on featuregit checkout -b feature/new-ui# ... make changes ...git add .git commit -m "feat: redesign homepage UI"# Push your workgit push origin feature/new-ui