Remotes and GitHub

Push a branch

Publish local commits and connect a new local branch to its remote counterpart.

Pushing sends your local commits to a remote repository. Nothing reaches the server until you push. Staged or uncommitted edits stay on your machine.

In notes-project, create the add-search branch and make a commit there. Before pushing, inspect the local commits and remote configuration:

git status
git log --oneline --decorate -3
git remote -v

Publish the branch with:

git push -u origin add-search

On success, Git prints something like:

 * [new branch]      add-search -> add-search
branch 'add-search' set up to track 'origin/add-search'.

Git sends objects the remote needs and updates your origin/add-search remote-tracking reference. The -u option records the upstream relationship. Later, plain git push and git pull on that branch know which remote branch to use.

Verify it:

git branch -vv

You should see add-search tracking origin/add-search.

A push can be rejected when the remote branch contains commits your local branch does not have:

! [rejected]        add-search -> add-search (fetch first)

Someone else pushed to the same branch while you were working. Do not immediately force-push. Fetch with git fetch origin, inspect with git log --oneline add-search..origin/add-search, merge or rebase their commits into your branch, then push again.

If you never pushed this branch before, you forgot -u once and Git still pushes, but git branch -vv shows no upstream. Run git push -u origin add-search once to fix tracking.

Pushing main before adding a remote fails with fatal: 'origin' does not appear to be a git repository. Add origin first with git remote add, then push.

After the first successful push, git status on add-search may say Your branch is up to date with ‘origin/add-search’. That message confirms the upstream link from -u.

Pushing does not send uncommitted changes. Edit ideas.txt without committing, run git push, and the remote branch still lacks that edit. Only commits transfer.

Try this: modify notes.txt without committing, push add-search, and confirm the remote did not receive the working-tree edit.

Lesson completed