0%

Remotes, Without a Server · practice

Push Main and Set Its Upstream

The bare origin.git exists, but it has no or yet. A push sends commits and updates a ref in another repository. You will push garden’s main branch and record which remote branch it normally exchanges with.

Read the push command

git push sends history and a ref to a remote. In git push -u origin main, origin selects the saved remote and main selects the branch to send. The option -u is short for --set-upstream: after the push succeeds, it records origin’s main as the upstream of local main.

An upstream is the default remote-branch relationship for a local branch. Once local main tracks origin’s main, later pushes from main can use plain git push, and git status can compare the two positions.

Run the first push:

git push -u origin main

Git creates main in origin.git. It also creates or updates origin/main inside garden. That slash does not mean a directory: origin/main is a remote-tracking ref, the local record of the remote branch position your repository last saw.

Read the two positions

You already know that git log reads commit history. Supplying a ref after it asks Git to start at that ref instead of at the current branch. Read local main, then the local record named origin/main:

git log main
git log origin/main
git status

Both logs currently start at the same commit, and git status reports that local main is up to date with origin/main. They are two refs that happen to agree after this push, not one shared pointer.

What did -u add to the successful first push?

Two separate things happened in that one command, and they are worth pulling apart. Your commits were copied into the bare repository, and a relationship was written down so that you never have to name the remote and the branch again. The first is the work. The second is the convenience, and it is why git push on its own will be enough from here on.