Git remote warehouse commands
🌿 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.
The remote is just an address pointed to by the name. Changing the address or changing the name will not affect the existing submission history.
name points to address
The local warehouse does not directly remember a URL, but gives the address a name first. For example, the commonly used one is called the default remote, and the address is addressed by name when pushing and pulling. In this way, when changing servers or migrating warehouses, you only need to change the address corresponding to the name once, and the other commands do not need to be touched. Understanding this indirect relationship can explain why changing the address will not affect history.
Four types of common operations
- Add: Register a new address as a name, usually used to associate with a remote location for the first time.
- Address change: The same name is changed to a new address remotely, which is common in warehouse migration or when the protocol is changed from encryption to encryption-free.
- Rename: Change the remote name, and the address and history will remain unchanged.
- Delete: Disassociate, the local warehouse and submission will not be affected at all.
Multiple remote uses
A repository can register multiple remotes at the same time: a main repository for team collaboration, and another for its own backup or mirror. The remote push to is completely determined by the name in the command, which provides convenience for "pushing to both the team warehouse and personal backup". The corresponding relationship between branches and remotes can also be set separately.
How to change the address if it has changed?
When the warehouse changes its domain name or moves from one protocol to another, you only need to update the remote address, and local submissions, branches, and tags will not be affected. After making the change, it is recommended to check the remote address to confirm that it has taken effect, and then try pulling again. If multiple remotes are used at the same time, be careful to only change the one that needs to be changed, and do not overwrite the mirror address.
To migrate a warehouse, you only need to change the remote address, and local submissions and branches will not be affected.
📖 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
❓ FAQ
- Will deleting the remote delete the code??
- No. Deletion only removes the local association with the address, and the warehouse on the remote server remains intact.
- Can it be pushed to two remotes at the same time??
- Yes, but you need to execute push commands separately or configure multiple addresses yourself. The tool only targets one remote assembly command at a time.