git remote add origin <url>Give an existing remote repository the nickname origin.
Create an empty GitHub repository first, then use its URL. This does not upload files.Explore this lesson
See what happens behind every command.
Type a command or choose a quick command. Your simulated history stays here when you switch tabs.
mainClick a commit to inspectGitHub hosts your online copy. Teamwork is a separate path.
19 commands found
git remote add origin <url>Give an existing remote repository the nickname origin.
Create an empty GitHub repository first, then use its URL. This does not upload files.git init -b mainTurn a folder into a Git repository; name the first branch main.
Run once when starting a new local project.git clone <url>Download a repository and its history.
Creates a local copy with origin configured.git statusInspect your branch, staged changes, and unstaged changes.
A useful first step whenever you feel lost.git diffSee the changes between working files and the staging area.
Use git diff --staged to inspect your next commit.git add <file>Stage the file’s current content for the next snapshot.
If you edit it again, stage it again to include that edit.git commit -m "message"Record the staged snapshot in your local history.
A commit does not publish anything to GitHub.git switch -c featureCreate a branch and start working on it.
The new branch initially points to your current commit.git switch mainSwitch your working files and HEAD to main.
Save or stash changes before switching when necessary.git merge featureIntegrate feature into your current branch.
Can fast-forward, create a merge commit, or stop at conflicts.git fetch originDownload history and refresh remote-tracking branches.
Does not integrate changes into your current branch.git pull --ff-only origin mainFetch and update your current branch only if it can fast-forward.
Diverged branches require an explicit merge or rebase decision.git push -u origin featurePublish feature and set its upstream tracking branch.
Push can be rejected if the remote has incompatible updates.git log --onelineRead the commits reachable from your current branch.
Each short ID identifies a saved snapshot.git revert HEADCreate a new commit that reverses the latest commit.
Suitable for undoing a mistake in shared history.git restore <file>Discard unstaged edits in a tracked file.
Destructive: check git diff first. Not simulated here.git restore --staged <file>Remove a file’s changes from the staging area.
Keeps the edits in your working directory.git stashTemporarily save local changes for later.
Use git stash pop to reapply them; conflicts can occur.git reset --soft HEAD~1Move the branch back one commit, keeping changes staged.
Rewrites the local branch. Avoid changing shared history.