The “git remote” command helps you to manage connections to remote repositories, git remote command is one piece of the broader system which is responsible for syncing changes. Git remote command is used with Git Fetch <origin>, Git Push <origin> and Git pull <origin> commands for processing of records or data registered through it.
Git remote command is used to configure remote server
This provides the remote name as the origin. Default name of the remote server is origin name provided by Git remote command.
It supports a specific option -v to show the URLs that Git has stored as a short name. Reading and write operation uses these short names. Here -v means verbose
git remote -v
This provides available remote connections. If a repository contains more than one remote connection, this command will show all of them.
When we fetch a repository in a way that is not directly expressed, git adds a remote for the repository. we can also explicitly add a remote as a petname for a repository using git remote add
git remote add <petname> <remote-url>
In the above screenshot, we have added a remote repository with an existing repository as a short name “drillers”. Now, you can use “drillers” on the command line in place of the whole URL. For example, you want to pull the repository, have a look on below screenshot
We have pulled a repository using its short name instead of its remote URL. Now, the repository master branch can be accessed through a petname.
You can also fetch and pull data from the remote repository. Git Fetch <origin>, Git Push <origin> and Git pull <origin> commands goes to remote server identified by origin and fetch data or push of provided version (default is HEAD) from/to provided branch (default is master) to sync with local directory.
Run the below command to fetch data from remote projects
git fetch <remote>
Before this let us create a new file in our remote repository and then we will use above command to see whether it fetches our changes or not
To create a file directly in your remote repository follow the below steps
- Go to your remote repository and click on create new file
- Enter the name of the file and enter some content in that file
- Click on commit new file
In our demo case we have created a file named remotedemo in our remote repository
To check fetch using remote execute
git fetch <remote>
To clone the remote projects
git clone <remote>
Whenever we clone a repository, the remote repository is added by a default name “origin.” This is the reason why most of the commands are used as git fetch origin, git pull origin.