Git Push

What

The git push command uploads your local commit history, branch pointers, and database objects up to a remote repository (like GitHub).

How

Specify the name of the remote destination and the branch you want to push:

# Push commits on local branch 'main' to the remote 'origin'
git push origin main

To configure Git to automatically link the local branch to the remote branch for all future pushes without having to type origin <branch> every time, use the -u (set-upstream) flag:

# Push and set upstream tracking link
git push -u origin main

Advanced operations:

  • Pushing to a differently-named remote branch:
    git push origin local-branch-name:different-remote-name
  • Deleting a remote branch:
    # Delete a remote branch named 'feature-branch'
    git push origin --delete feature-branch
    
    # (Alternative legacy syntax) Push an empty branch to the target remote branch
    git push origin :feature-branch

Why

Writing code locally is only half the battle. Pushing updates the centralized copy of your codebase on GitHub’s cloud servers. Once pushed, your changes are permanently saved off-site and immediately visible to automated delivery systems or other developers collaborating on your team.

Summary

Use git push origin <branch_name> to safely upload your local commit history and branch updates to your remote repository.