World map

 

BM: Baca dalam Bahasa Melayu

World 4: Hello GitHub

Your first push

You will learn: how to send your commits to GitHub with git push.

The problem

Your diary has 3 commits. Your GitHub repo is empty. What carries the commits up there?

Pick one answer.

Watch

A courier carries three commits from your laptop to the empty GitHub repo. Now GitHub's main matches yours, and your laptop shows origin/main.

Your laptop~/diary
  1. ea2c020Add purple style (only on your laptop)main (HEAD is here)
  2. f6c78e5Add home page (only on your laptop)
  3. 2efd0f2Add README (only on your laptop)
Not linked to a GitHub branch yet
GitHubgithub.com/you/diary
Empty. No commits yet.

A push: Send your new commits to a remote, like GitHub. is a courier. It carries your new commits up to GitHub. git push -u origin main sends main to origin.

Watch

The push says main set up to track origin/main. Then git status says: Your branch is up to date with origin/main. Terminal output: $ git push -u origin main To https://github.com/you/diary.git * [new branch] main -> main branch 'main' set up to track 'origin/main'. $ git status On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean

-u sets the upstream: The remote branch your branch follows, like origin/main. For a fork, also the usual name for the original repo.: main now follows origin/main. From now on, plain git push knows where to go.

Try it

Your turn. Tap a command and watch the courier.

Your laptop~/diary
  1. ea2c020Add purple style (only on your laptop)main (HEAD is here)
  2. f6c78e5Add home page (only on your laptop)
  3. 2efd0f2Add README (only on your laptop)
Not linked to a GitHub branch yet
GitHubgithub.com/you/diary
Empty. No commits yet.

Tap an action. Watch the courier.

Predict

Nothing is new. You run git push again. What does Git say?

Pick one answer.

Try it

You added an about page. Send it with the short command.

2efd0f2f6c78e5ea2c0208de16c3

You did it!

You can now push your commits to GitHub.

Go deeper (optional)

git config --global push.autoSetupRemote true makes plain git push set the upstream for new branches too. git push origin --delete old-branch deletes a branch on GitHub. Pushing a new branch makes GitHub print a pull request link.