There are some operations with git remote, such as git remote
-v, that you can use occasionally
But, the concept of a remote control within Git is important and powers many of the other operations
What does Git remote do? Git
Remote manages the set of remote controls you are crawling with your local repository.
Common git remote commands
- -v: List the current remote controls associated with the local repository
- remove [name]: Remove a remote control
git remote add [name] [URL]: Add a remote control git
? If you try to run git remote -v in your repositories, you’ll probably see something called origin. You can notice the origin in many Git messages. origin is the friendly name for the URL where the remote repository is stored. It’s like a pair of key values, and the source is the default.
What is upstream?
You may need or want to work with multiple remote controls for a local repository. This can be common in open source, when a contributor needs to create a fork of a repository to have permission to push changes to the remote control.
In this case, it is common to create and clone a branch. So, the default remote control would be origin, referring to the branch. To make it easier to pull any changes to update the local copy of the original repository branch, many people also add the original repository as remote. It is typical to name this remote control upstream.
are four commands within Git that request communication with the remote. Unless you’re using one of these four commands, all your work only happens locally.
- git push
- git fetch
the remote control The concept of
branches can be confusing once combined with the concept of remote controls. Git keeps track of the branches you work on locally, as well as each of the branches in each remote control associated with your local repository.
Remote tracking branches
If you run the git -all branch in your repository, you’ll notice a long list of branches. The branches that (by default) appear in red are the remote tracking branches. These branches are read-only copies of the branches on the remote control. These are updated every time you run git fetch or git pull.
These don’t take up much space, so it’s okay for Git to do this by default. But, these will accumulate over time, they are not automatically deleted.
To delete remote tracking branches that are deleted on the remote control, run git fetch -prune. This is safe to do if you are using GitHub, because branches merged through pull requests can be restored.
Local work branches
run git branch -all, you will also see the local work branches. These may be linked to branches in the remote, or they could exist without a remote counterpart.
- git clone [url]: Clone (download) a repository that already exists on GitHub, including all files, branches, and commits
- status: It’s always a good idea, this command shows you which branch you’re in, what files are in the working or staging directory, and any other important information. git
- push: Loads all local branch confirmations to the remote control.
- git pull: Update your current local work branch with all new commits from the corresponding remote branch on GitHub. Git Pull is a combination of Git Fetch and Git Merge.
Contribute to this article on GitHub.