Learn how to generate single page apps with Claude AI. Get the ultimate base prompt, app ideas, and functional examples to build web apps instantly.

Learn the essential Git commands for version control. Master starting a project, branching, staging, committing, and collaborating with this Git 101 guide.

Git is a distributed version control system that tracks code changes, enabling multiple developers to collaborate seamlessly on a codebase. By mastering the core Git commands, developers can manage project history, work on isolated features via branching, merge contributions, and maintain an organized, collision-free workflow. This Git 101 guide covers the essential commands you need to know.
git init -> Create a new, empty Git repository in the current directory.
git clone <project_url> -> Copy an existing remote repository into a local folder.
Cloning automatically sets a remote named origin.
Remote vs Alias
Remote -> A link (URL) to another Git repository.
Alias -> A nickname for that remote URL, so you don't have to type the full URL.
By convention, origin is the alias for your own fork/cloned copy, while upstream usually refers to the original repo you forked from.
git config -> Set or view configuration (e.g., username, email, editor).
git remote add [alias] <project_url> -> Add a shortcut name (alias) for a remote repository.
git branch -> List, create, or delete branches.
git branch -d [branch_name] -> Delete branches.
git branch -m [old_branch_name] [new_branch_name] -> Rename branch.
git checkout -> Switch branches or restore files.
git checkout -b [branch_name] -> Create a new branch and switch to it.
git status -> Show modified files and staging status.
git add [file] -> Stage a file for the next commit.
git add . -> Stage all changed files in the directory.
git mv [file] -> Rename or move a file and stage the change.
git rm [file] -> Remove a file and stage the deletion.
git diff -> Show changes not yet staged.
git commit -> Save staged changes as a new commit.
git commit -m [message] -> Commit with a message in one step.
git fetch [alias] -> Download changes from a remote without merging.
git pull [alias] [branch] -> Fetch and merge changes from a remote branch.
git push [alias] [branch] -> Upload local commits to a remote branch.
git stash -> Temporarily save changes without committing.
git checkout . -> Discard local changes in tracked files.
NOTE
git stash if you may want your changes later.git checkout . if you want to throw away changes permanently.git merge [alias]/[branch] -> Merge a branch (often from remote) into the current one.
git rebase -> Reapply commits on top of another branch for a cleaner history.
Flow to collaborate with someone else's repo
git log -> Show commit history.
git log [branch_name] -> Show commit history of a specific branch.
git log --oneline → Show condensed commit history (one line per commit).
Commit history
5e7bfbf (HEAD -> main, origin/main) Fixed feature bug
5a50202 Added dashboard page
0d2fd4e Initial commit
git reset --hard -> Discard all local changes (unstaged and staged) and resets files to the latest commit.3 states of tracked files
git reset --hard HEAD~1 -> Remove the latest commit completely.Let's say the last commit was:
Last commit
echo "hello" > newfile.txt
git add newfile.txt
git commit -m "add new file"
After running git reset --hard HEAD~1:
newfile.txt is gone (deleted from your folder).
Commit "add new file" is gone.
Repository is back to the state before you created newfile.txt.
-u (--set-upstream) in git push -u origin main? Without -u
git push origin main
git pull origin main
You always need to specify the remote + branch if not using -u.
With -u
git push -u origin main
git push
git pull
Git remembers the tracking relationship. After the first push, you can simply run git push or git pull and Git will know you mean origin main.
git commit? To add file(s) after git commit, run:
Git
git add [file]
git commit --amend
git fetch vs git pull? git fetch downloads new branches from the remote while git pull is git fetch + git merge.
Happens when your local branch is ahead of the remote branch (remote doesn’t have new commits).

If there’s no conflict, remote will fast-forward update.
Happens when the remote branch has commits that your local branch doesn’t.

git push rejected because commits E and F exist only on remote.
Steps to resolve a merge with conflicts
git pullgit add .git commitgit push to update the remote branch.git merge? Run git merge --about if not committed yet.
Run git reset --hard HEAD~1 if committed but not pushed.
git merge main vs git merge origin/main? git merge main is local branch merge while git merge origin/main is remote-tracking branch merge.
Local branch merge
git checkout new-feature
git merge main
You are on new-feature.
Git takes the local branch main and merges it into new-feature.
Both main and new-feature are local branches.
Remote-tracking branch merge
git fetch origin
git checkout new-feature
git merge origin/main
git fetch origin updates your local copy of remote-tracking branches (like origin/main).
You are on new-feature.
Git merges origin/main (remote-tracking branch / local-copy of remote branch) into your local branch, new-feature.
Make small, focused commits that represent one logical change.
Write clear, descriptive commit messages (e.g., Fix auth bug instead of Update code).
Keep your main or master branch stable.
Create new branches for new features, bug fixes or experiments.
git pull before pushing changes to avoid conflicts.git branch -d [branch_name] after merging.Tags