Hongmu Notes

Git push command

Pushing is to send local submissions to the remote; remember to bind the upstream when pushing a new branch for the first time, and you can omit parameters later.
100% Browser local processing 0 Data upload

🌿 Command assembly

💡 Instructions for use

  • The branch name and remote name must be written correctly. Misspelled commands often do not report an error but take effect on other branches.
  • Commands involving reset, force push, and rebase will rewrite history. Please confirm the branch and target before execution.
  • Check Bind Upstream when pushing a new branch for the first time. You can omit the remote and branch names for subsequent pushes and pulls.
  • The command is output in a single line, making it easy to paste directly into the terminal; it is recommended to save the steps that need to be repeated into a script.

Pushing is to send local submissions to the remote; remember to bind the upstream when pushing a new branch for the first time, and you can omit parameters later.

Rules for writing parameters

The parameter order of the push command is fixed as follows: write the remote name first, then the branch name to be pushed. When omitted, it will be inferred based on the current branch and the bound upstream. Therefore, after binding the upstream, daily synchronization can be completed by pushing alone. If the local branch name is different from the remote branch name, you can also write a pair of names to push the local branch to another remote branch name.

Pushing a new branch for the first time

When the new branch does not exist in the remote yet, you need to explicitly specify the remote and branch, and it is recommended to bind the upstream relationship at the same time. After binding, the local branch will remember the corresponding remote branch, and then push and pull directly. When viewing the status, you can also see how many commits are ahead or behind. In team collaboration, it is common practice for everyone to bind upstream for feature branches.

Risks of forced push

  • Force push will overwrite the remote with local history, and commits pushed by others will disappear from the remote.
  • Forced push with security verification will check whether the remote has been updated by others before overwriting, which is relatively safe.
  • Only use it on your own exclusive feature branch. Do not force shared branches.

Push tags to other branches

Tags will not be automatically uploaded with ordinary push. You need to explicitly push specified tags or push all tags at once. In the same way, the default target of push is the current branch. If you want to push other branches, you need to specify the branch name. After the push is completed, it is recommended to check whether the corresponding branch or tag appears on the remote to avoid mistakenly thinking that it has been synchronized.

Do not force push the shared branch, as it will overwrite the commits already pushed by collaborators.

📖 Glossary

workspace
The directory where the file being edited is located. The modified content that has not yet been registered only exists in the workspace and may be overwritten by any rollback, so important changes must be submitted first.
Staging area
A preparation area between the work area and the warehouse. Submissions only record the contents of the staging area, so a batch of changes can be split into several submissions, or only part of them can be submitted.
Submit
Solidify the contents of the temporary storage area into a historical node, with description, author and time. Once a submission is generated, it has a unique number, which is used as the minimum unit for rollback and tracing.
branch
A movable pointer to a commit, used for parallel development of changes that do not affect each other. A new branch takes up almost no space. Switching branches means that the work area and temporary storage area follow the pointer.
head pointer
A pointer that marks the current location, usually pointing to a branch. If it points directly to a commit and is not on a branch, it is a detached head state, and the new commit at this time will not update any branches.
merge
Merge the history of another branch into the current branch to generate a new merge node. If the two branches do not diverge, they will be fast forwarded directly and no merge node will be generated.
Rebase
Move a series of commits on the current branch to another branch and replay, so the history becomes a straight line. Do not rebase the submitted commits that have been pushed out, otherwise the local history of the collaborators will be inconsistent.
reset
Move the current branch pointer to the specified commit. The three modes respectively determine whether to modify the staging area and the work area at the same time. The mode of changing the work area will directly discard uncommitted modifications.
Remote warehouse
A copy of the same repository located on the server, referenced locally by a name. You can change the address or name of the same remote. Both push and pull are addressed by name.
upstream branch
Establish a corresponding relationship between the local branch and the remote branch. You can omit the remote name and branch name when pushing and pulling after binding, and you can also directly see how many commits are ahead or behind.
label
A fixed name given to a commit, often used to mark versions. Tags with descriptions will generate an additional object containing the author and time. This is recommended for release versions.
storage
Put away unfinished changes temporarily to return the workspace to a clean state and retrieve them when needed. It is suitable for situations where you are called to fix an urgent problem midway but do not want to submit it hastily.

🔗 All keywords and tutorials

Keywords page of the tool12a

Return to tool home page

❓ FAQ

Why do I have to write the remote name every time??
Because the branch has not yet been bound to the upstream. Add binding parameters when pushing for the first time, so you don’t need to write them again later.
How to push the label?
Tags will not be automatically uploaded with the branch. You need to push specified tags individually or push all tags at once.