Gregory Dvorkin
Gregory Dvorkin

Reputation: 43

Can I connect my local Git to different server accounts?

I work at home and would like to connect different Gits independently from each other. Cannot figure out if it is possible. E.g. for work I would need to connect company's repository using my company's email. Company uses Git in Azure DevOps (former cloud VSTS or TFS) For my personal use I would need to connect my account in GitHub or my personal account it Azure DevOps. I am doing it mainly for learning or PoC purpose.

No need to merge both, I am just the beginner with Git, so asking at least to point me to the right direction. I did not find the example that would match exactly my need.

Adding for clarification: I want to understand how I can configure the following on my desktop using Git command line or Eclipse Git plugin: 2 independent projects both using different independent remote repos with different accounts.

Upvotes: 1

Views: 70

Answers (1)

torek
torek

Reputation: 488193

The answer to the question as asked is yes: one Git can connect to any other Git. Well, provided there is some internet connection, or—with git bundle—some sort of sneaker-net connection.

The answer to another question, about whether this would be useful, is more complicated. (And the answer to a third question, whether your company might approve or not, is political rather than technical.)

Git is, in the end, all about commits as identified by hash IDs. To get useful work done in separate Gits, they need to share the actual commits and thus the hash IDs. That's why we use git clone: this copies the commits by their hash IDs.

When you make a clone of some other Git repository, you get all of its commits and none of its branches.1 The clone process receives their branch names, but modifies them, so that they become your remote-tracking names. Your Git then creates one branch name in your copy of the repository. This one branch name points to the same commit as one of their branch names, which are now your remote-tracking names.

From this point on, you do work with the commit hash IDs, using your own branch name(s), which you create based on the hash IDs stored in their branch names, which you've copied to your remote-tracking names. You now have your own branch names, but all the commits are shared—except for any new commits that you create, and any new commits they create after you run git clone.

To have your Git and their Git co-ordinate, you and they need to share most of the hash IDs and commits. So a clone of your clone, or of their clone, is good: these all share lots of hash IDs, and therefore lots of commits.

To the extent that you're cloning clones of clones of the clones that cloned clones of clones 😀, this all works out pretty well. It all goes wrong when you connect two unrelated repositories, where the hash IDs don't match up in any commits at all.


1Technically, you get all the reachable commits from some set of names, where the set of names is up to you. Typically, though, you use all of their (public-visibility, branch and tag) names to create all of your names, so that you get all their commits. Your Git copies their tag names and renames their branch names, so you share tag names, but have your own unique branch names.

All of this can be controlled, but that's Advanced Git, not Git 101.

Upvotes: 1

Related Questions