Search code examples
gitgithubbitbucketssh-keysgit-repo

Switching between projects in different Repository Management Services (bitbucket, GitLab) using git


I have already a project on GitLab which I've been working on, and recently I've been assigned another project on bitbucket.

I already understand that when I work on a project and I need to push, pull, add, commit etc. then I need to ensure I'm already in that project's directory, but what other factors do I need to be aware of? I'd like to avoid any conflicts or embarrassing situations like committing code to the wrong project, so perhaps I need to switch between different repos.

A while back a former colleague configured in my .bash_profile file. The below commands were for a project I no longer work on, so I don'T use this anymore but it's still there in my .bash_profile file:

set_companyX_git(){
  git config --global http.sslcertpasswordprotected true
  git config --global http.sslCert /Users/my_mbp/Software/ssl_project/keystore.p12
}

unset_companyX_git(){
  git config --unset --global http.sslcertpasswordprotected
  git config --unset --global http.sslCert
}

I'd like to add something similar in my .bash_profile again, but I'm not sure how correct these commands are. Hopefully a git pro can put me on the right path here.

Due to my existing project on Gitlab I'll already have a ssh key, but must this key be individual to every repo, or to every Repository Management Services, or does it not matter so long as I have a key?


Solution

  • A bunch of questions here, but I'll answer them as best I can in the order they were asked.

    1. what other factors do I need to be aware of? - Your commits will all have the author details (name and email address) specified in your global config. If that's acceptable, then great; if that might cause a problem, then you may need to run git config user.name "Your Name for This Repo" and git config user.email "foo@bar.baz" in each repo that needs to differ from the global config.
    2. I'd like to add something similar in my .bash_profile again, but I'm not sure how correct these commands are. Those should only be necessary if you have to provide a password for a TLS key. If you aren't hosting repos locally, then you probably don't need them.
    3. must this key be individual to every repo, or to every Repository Management Services, or does it not matter so long as I have a key? It doesn't matter as long as you have a key, though each remote host will limit that key to one user account. (In other words, if you have UserA on GitLab and UserB on Bitbucket, then you can use the same key for both - but if you have both UserA and UserB on GitLab, then they'll need separate keys.)