In the previous section, we added a remote repository "git_examples" which was pointing to Now if you want to change the URL of the "git_examples" remote repository to # git remote set-url git_examples git remote -v Here is an example to illustrate the difference between the two commands: This command updates the URL of the remote reference in the local repository's configuration, allowing you to switch the remote repository to a different URL. The git remote set-url command, on the other hand, is used to change the URL of an existing remote repository. Remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0įrom :golinuxcloud/git_examples Remote: Compressing objects: 100% (2/2), done. Remote: Counting objects: 100% (4/4), done. You can now use git pull along with your branch name to pull the changes from respective branch: # git pull git_examples test This will display a list of all the remote repositories that have been added to the local Git repository. Verify that the remote repository has been added by using the git remote -v command. For example, to add a remote repository named "origin" with the URL " you can use the following command: # git remote add git_examples Verify Remote Repo Once you are in the correct directory, you can execute the git remote add command with the correct syntax to add the remote repository. You can navigate to the root directory of the local Git repository using the cd command in the terminal. Get the URL of the repository, in my case it is You can get this information under Clone button as shown below: In such cases you first need to initialize a new Git repository in that directory using the git init command. If you are starting on a fresh Linux or Windows server where git is not initialized and you attempt to add remote git server, then you will get: fatal: Not a git repository (or any of the parent directories). ![]() This command adds the remote repository named "origin" to your local repository's configuration, sets the URL to " and specifies that you want to track the " master" branch on the remote repository.ĭetailed steps to add remote repository Pre-requisite - Initialize Git Repository For example, you can use the -t option to specify the branch that you want to track on the remote repository: git remote add origin -t master I have created a repository on GitLab which I will be using in this tutorialįor example, if you want to add a remote repository named " origin" with the URL " you would use the following command: git remote add origin command adds the remote repository named "origin" to your local repository's configuration and sets the URL to " can also specify additional options when using git remote add. To practice how git remote add function works, you will prepare a lab environment to run the experiments. Finally, run the command git push -u origin master to push the changes to the new remote repository on the master branch. ![]() Run the command git commit -m "Initial commit" to commit the changes.to add all the files in the directory to the staging area. Replace with the URL of the new repository that you copied earlier. Run the command git remote add origin to add the new remote repository as the origin.Run the command git init to initialize the directory as a new Git repository.For example, if you want to create a new Git repository in the directory /home/user/myproject, you would run the command cd /home/user/myproject. Open a terminal window and navigate to the directory that you want to initialize as a Git repository.For example, if you are using GitHub, the URL will be in the format. For example, if you are using GitHub, you can create a new repository by clicking on the "New repository" button on your dashboard. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |