Menu
×
     ❯   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

Git Push to GitHub


Git Push to GitHub

When we have made changes locally, we want to update our remote repository with the changes.

Transferring our local changes to our remote is done with a push command.

There are several commands we can use to push changes to GitHub.


Key Push Commands


Basic Push

This command pushes your current branch to the remote repository named origin:

Example

git push origin

This will upload your local commits to GitHub.

You must have already committed your changes with git commit.



Force Push

If your push is rejected due to non-fast-forward updates (for example, after a rebase), you can force the push.

Warning: This can overwrite changes on the remote repository. Use with caution!

Example

git push --force origin feature-branch

Use --force-with-lease for a safer force push:

Example

git push --force-with-lease origin feature-branch

Push Tags

To push all local tags to GitHub:

Example

git push --tags

To push a specific tag:

Example

git push origin v1.0

Troubleshooting

  • Non-fast-forward error: Happens if someone else pushed to the branch. Run git pull --rebase before pushing again.
  • Authentication failed: Make sure you have access to the repository and your credentials are correct.

Go to GitHub, and confirm that the repository has a new commit:

GitHub New Commit

Now, we are going to start working on branches on GitHub.


Exercise?What is this?
Test your skills by answering a few questions about the topics of this page

Drag and drop the correct command to upload local commits to the remote repository.
git origin
commit
send
push




×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.