Home > OS >  connecting to bitbucket and github from the same .gitconfig
connecting to bitbucket and github from the same .gitconfig

Time:06-20

I have a locally hosted version of bitbucket, and a github account. I want to be able to connect to both easily. I tried this .gitconfig version, does not work seamlessly. What Am I missing? What should I put under user in both systems?

#Github (default)
  Host gh
  HostName github.com
  User ?
  IdentityFile ~/.ssh/id.pub

#Bitbucket (secondary)
  Host bb
  HostName stash.company.com
  User ?
  IdentityFile ~/.ssh/id.pub

CodePudding user response:

In your local repo, a "remote" is defined to tell git what repository to go to when doing things like push and pull. The default name is "origin". So we enter commands like "git pull origin main"

The command "git remote -v" will show the "remotes you have defined, like this:

git remote -v origin [email protected]:/.git (fetch) origin [email protected]:/.git (push)

You can define another remote to point to a different remote repo: git remote add

So if you add a remote and call it bborigin then git pull bborigin main would pull the main branch on remote bborigin

(I do not know if you will need special steps to set up authentication on the different remotes)

CodePudding user response:

First, you need to put that in ~/.ssh/config

That means you can:

  • test your authentication with ssh -Tv gh or ssh -Tv bb
  • use those Host entries in SSH URLs with
    • git clone gh:me/myGitHubRepository
    • git clone bb:me/myBitBucketRepository

Second, a typical global .gitconfig (in $HOME\.gitconfig) would look like:

[alias]
        st = status
        lg2 = log --graph --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)           
  • Related