Push
In Git, pushing is the process of moving code from one repository to another one. Often this is used to move code from a local machine to a remote one, or to a repository hosting service like GitHub.
Pushing a repository allows a programmer to maintain an easily accessible backup in a second location. It is also used when collaborating with people that would not have access to the computer that the code is written on.
Syntax
The syntax for pushing changes in Git is this:
git push <remote-name> <branch-name>
How to Push
Prerequisites to pushing from within a repository include:
Being inside of a repository (if not, the next step will return an error)
Having a clean
git status
(no uncommitted, but tracked, files):$ git statusOn branch mainnothing to commit, working tree cleanHaving a valid remote repository set. In this case the remote repository is named
origin
and can be found at the urlhttps://github.com/CompanyName/product-dev
:$ git remote -vorigin https://github.com/CompanyName/product-dev.git (fetch)origin https://github.com/CompanyName/product-dev.git (push)
At this stage, pushing can be accomplished with a valid remote and branch name:
git push origin main
When the push completes, it will display a message like this:
Enumerating objects: 5, done.Counting objects: 100% (5/5), done.Writing objects: 100% (3/3), 304 bytes | 304.00 KiB/s, done.Total 3 (delta 0), reused 0 (delta 0), pack-reused 0To https://github.com/CompanyName/product-dev.git0e21f7b..2a668cb main -> main
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Git on Codecademy
- Course
Learn Git & GitHub
Use our beginner friendly Git course to integrate Git and GitHub and manage versions of your projects using Git branches.With CertificateBeginner Friendly4 hours - Course
Learn the Command Line
Learn about the command line, starting with navigating and manipulating the file system, and ending with redirection and configuring the environment.With CertificateBeginner Friendly4 hours