Reputation: 59
I want to add multiple git servers in my repository and to push data to 1 server and fetching it from another server. I am new to git.
Upvotes: 5
Views: 7267
Reputation: 24478
Git repositories know about other git repositories with remotes. A remote is basically just an entry in your .git/config
file that remembers the URL of another git repository somewhere, and gives it a name.
When you run git clone
, you're automatically given a remote called "origin" that remembers where you cloned from. You can add additional remotes like so:
git remote add some-name https://someserver/some/path.git
git remote add other-name https://otherserver/other/path.git
Git understands URLs in a variety of formats, including http(s), ssh, or even raw paths. Your servers should give you some indication of the URL to use.
Once you've defined your remotes, you can push or fetch data by using the remote names you've used:
# Push to "someserver"'s master branch
git push someserver master
# Fetch new work from "otherserver"
git fetch otherserver
# ... and merge its master branch in to the current branch:
git merge otherserver/master
Upvotes: 3
Reputation: 9624
You just need to add the remotes to your repository. In your local repo, do this:
git remote add fetch_remote http://<link to remote>
git remote add push_remote http://<link to remote>
Verify by doing a git remote -v
You can then pull from and push to your remote repositories as you wish.
Upvotes: 1
Reputation: 2743
You can add as many remotes as you need:
git remote add fetchy [email protected]:path/to/repo.git
git remote add pushy [email protected]:path/to/repo.git
Then, it's as simple as:
git fetch fetchy
git checkout -t fetchy/your-branch
# do work and commit changes
git push pushy your-branch
Upvotes: 1
Reputation: 18803
Get acqainted with the Git Documentation.
For your question:
Upvotes: 0