noknow.dev
Sign inSign up
Course overview
Git — Complete Course
0 / 24 lessons0%

Git Basics

  • git init — Starting a Repository
  • git add + git commit — Your First Commit
  • git status + git log — Reading the State
  • git diff — Seeing What Changed
  • .gitignore — Ignoring Files

Branching

  • git branch + git switch — Working with Branches
  • git merge — Combining Branches
  • Resolving Merge Conflicts
  • Cleaning Up Branches

Remote Repositories

  • git remote — Connecting to a Remote
  • git push — Uploading Your Commits
  • git fetch + git pull — Getting Remote Changes
  • git clone — Copying a Repository

Undoing Changes

  • git restore — Discarding Uncommitted Changes
  • git reset — Moving HEAD Back
  • git revert — Safely Undoing a Commit
  • git stash — Temporarily Saving Work

Rewriting History

  • git commit --amend — Fixing the Last Commit
  • git rebase — Cleaner History
  • git cherry-pick — Applying Specific Commits

Advanced Tools and Workflows

  • git tag — Marking Releases
  • Mastering git log
  • git bisect — Finding Bugs with Binary Search
  • Professional Git Workflows

git push — Uploading Your Commits

0m 00s

Sending Your Work to the Remote

# First push — set the upstream branch
git push -u origin main

# Subsequent pushes (upstream already set)
git push

# Push a specific branch
git push origin feature-x

The -u flag (or --set-upstream) links your local branch to the remote branch, so future git push / git pull know where to go without specifying the remote and branch every time.

Push rejection

Git refuses to push if the remote has commits you don't have locally:

# Remote is ahead — you must pull first
git pull --rebase     # get remote changes, put yours on top
git push

Force push (use with extreme caution!)

git push --force-with-lease  # safer: fails if remote has changed
git push --force             # dangerous: can destroy others' work

Your Task

A remote named origin is already configured. Push the main branch to it using -u.

Back
bashCtrl+Enter to run
Output

Click "Run" to execute your code.