git push
git push
: push changes to a remote repository.
The git push
command is used to upload local repository content to a remote repository. It's how you transfer commits from your local repository to a remote repo. It's the counterpart to git fetch
, but whereas fetching imports commits to local branches, pushing exports commits to remote branches.
Pushing has the potential to overwrite changes, so you need to be careful when you use it. These changes are pushed to the remote repository, potentially affecting other collaborators working on the same project.
When you push changes, you are updating the remote branch with your local changes. If someone else has pushed to the same branch in the meantime, Git will refuse the push and tell you to pull the remote changes first. This prevents you from accidentally overwriting someone else's work.
Pushing is the way you share your commits with other people and is a crucial part of collaborative development with Git. It allows everyone to see your work and enables them to incorporate your changes into their own repositories.
Examples
Let's say you've made some changes to your local repository, and you want to share these changes with your team. Here's how you would do it.
After committing your changes locally, push the new commits in your local branch named main
to the same branch on the remote repository named origin
:
git push origin main
If the branch doesn't exist, use the -u
option (short for --set-upstream
) to create it:
git push -u origin new-feature
Push all local branches to their corresponding remote branches:
git push --all
Force push, overwriting the remote branch with your local changes:
This action is DANGEROUS and should be used with maximum caution, because it can overwrite other people's work.
In normal circumstances, you should instead pull the remote changes first, rebase your own changes on top of the updates, while resolving any conflicts. Then you will be able to push your changes without using force.
git push --force
Hi! I'm Alex, creator of GitByBit.
And this is Gitopedia—a reference that summarizes knowledge in my Git course.
Gitopedia is designed to be a personal knowledge base. When you progress through the main Git course in VS Code, you unlock all of these topics, one by one, bit by bit. This gives you time to digest the information and gradually build the mental model of Git. Here's an example of how it works:
Learning directly in VS Code lets you practice Git exactly as you would in real life, doing real jobs, writing real code. In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.
The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.