Setting up a Git remote repository
This article will explain how to add or delete remote repositories.
A remote repository is a project hosted somewhere, such as Github/Gitlab.
Adding a remote repository allows us to use a short name (alias) to execute commands instead of typing the entire remote URL.
$ git fetch git@github.com:stwarts/git-demo.git
From github.com:stwarts/git-demo
* branch HEAD -> FETCH_HEAD
A default remote name called git clone
is automatically set when
using .origin
Its value is the cloned repository.
$ git clone git@github.com:stwarts/git-demo.git
Cloning into 'git-demo'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
$ cd git-demo
$ git remote -v
origin git@github.com:stwarts/git-demo.git (fetch)
origin git@github.com:stwarts/git-demo.git (push)
Use git remote -v
to list details of all remotes; to show just the names, use git remote
.
-
-v
Option stands for--verbose
, it displays the corresponding URL for each name.
$ git remote
origin
$ git remote -v
origin git@github.com:stwarts/git-demo.git (fetch)
origin git@github.com:stwarts/git-demo.git (push)
When initializing the repository locally, we need to explicitly add the remote.
git remote add <name> <url>
$ git remote add alice_git_demo git@github.com:alice/git-demo.git
$ git remote -v
alice_git_demo git@github.com:alice/git-demo.git (fetch)
alice_git_demo git@github.com:alice/git-demo.git (push)
origin git@github.com:stwarts/git-demo.git (fetch)
origin git@github.com:stwarts/git-demo.git (push)
We can git remote rename <old> <new>
rename an existing remote by running .
$ git remote rename alice_git_demo stwarts_git_demo
origin git@github.com:stwarts/git-demo.git (fetch)
origin git@github.com:stwarts/git-demo.git (push)
stwarts_git_demo git@github.com:alice/git-demo.git (fetch)
stwarts_git_demo git@github.com:alice/git-demo.git (push)
Use git remote remove <name>
to remove a tracked repository.
$ git remote remove stwarts_git_demo
$ git remote remove origin
$ git remote add stwarts_git_demo git@github.com:stwarts/git-demo.git
$ git remote -v
stwarts_git_demo git@github.com:stwarts/git-demo.git (fetch)
stwarts_git_demo git@github.com:stwarts/git-demo.git (push)
stwarts_git_demo
The name is ready for sharing data.
$ git fetch stwarts_git_demo
From github.com:stwarts/git-demo
* [new branch] main -> stwarts_git_demo/main
$ touch file.txt
$ git add file.txt && git commit -m 'Add file.txt'
[main 80bf058] Add file.txt
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file.txt
$ git push stwarts_git_demo main
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 281 bytes | 93.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:stwarts/git-demo.git
dd38fe8..80bf058 main -> main
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
.git Directory Explanation
Publish Date:2025/03/29 Views:65 Category:Git
-
In this article, we'll introduce Git folders .git . We'll cover why Git creates folders and what they contain. .git What are folders in Git ? Git is a widely used version control system. Git repositories store the changes you make in your p
Cherry-Pick Merge Commits in Git
Publish Date:2025/03/29 Views:105 Category:Git
-
When multiple developers from the same team are working on a project, regardless of the complexity of the project, handling and managing changes between Git branches becomes very difficult. Sometimes, we need to merge some specific commits
Fatal: Refusing to Merge Unrelated Histories error in Git
Publish Date:2025/03/29 Views:123 Category:Git
-
This article outlines the steps required to resolve the fatal: refusing to merge unrelated histories error in Git. We usually encounter such errors when trying to merge two unrelated Git projects into one branch. It pops up when the receivi
Clone a remote repository using submodules in Git
Publish Date:2025/03/29 Views:58 Category:Git
-
This article will discuss how to clone a remote Git repository using submodules. We will also create a submodule and push it to the remote repository before cloning it. Clone a remote repository using submodules in Git We clone our reposito
Using SSH keys to clone a repository or branch in Git
Publish Date:2025/03/29 Views:138 Category:Git
-
SSH Git cloning provides a secure way to clone remote repositories. This tutorial shows the complete method of Git cloning using SSH keys - how to generate SSH keys, set up SSH in Git, and use SSH keys for Git cloning. We also showed some u
Clone the repository in Git
Publish Date:2025/03/29 Views:146 Category:Git
-
Git is known as one of the best and most demanding version control systems for all developers around the world. As of now, it is a distributed version control system that utilizes its local repository and delegates the typical version contr
Clone Git using username and password
Publish Date:2025/03/29 Views:75 Category:Git
-
In this article, we will learn how to clone an existing repository using username and password in Git. In Git, we use the command git clone to clone an existing remote repository to our local computer. When we call git clone the command, we
Clone into a non-empty Git directory
Publish Date:2025/03/29 Views:108 Category:Git
-
This article will show you how to clone a Git repository to a non-empty folder. This operation comes in handy when you want to merge files from a remote repository with files in your current local repository. In Git, clone into a non-empty
Clone all branches in Git
Publish Date:2025/03/29 Views:132 Category:Git
-
When developing software using Git, you can create different branches for different features. This article will explain how to clone all different branches from remote to local in Git. Git clone all branches When using Git, you may need to