Git User Group

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple git developers on one Windows login

Solved!
Go to solution

We have to share one set of test hardware between multiple developers. Only one Windows login on the computer is allowed. We are using ssh keys with Atlassian Bitbucket and so we need to switch keys and Git ID when switching developers on the PC. Has anyone done this?

 

The brutal method would be to write a VI or Powershell script to just copy sets of keys into C:\Users\OneUserAccount\.ssh and change the ~/.gitconfig file —global name and email. Or do it by hand.

 

I was wondering if there was anything more built-in, like maybe in the ssh-agent. Oddly, it looks like this is a world-wide corner-use-case for Git, not much on google.

Chris Clark

0 Kudos
Message 1 of 13
(3,524 Views)

Is your goal to ensure that the commits are properly attributed to the individual developers? If so,

 

If only one person is making the changes at a time on this computer, then you could consider maintaining several .gitconfig files within the repo root folder, say (config.person1, config.person2, etc.) and have the local config file be set up as a shortcut to one of these developer-specific files. The additional task for each developer is, they would need to ensure that the shortcut points to their named config file before starting their work. The repo's gitignore could be set to ignore the shortcut and all these custom config files. (Note: I have never needed nor tried this approach. so it's a bit of a guess.)

 

If two or more persons are making changes concurrently (say, via remote desktop), then you could consider multiple clones. E.g. Person1Folder/repo, Person2Folder/repo. Here again, a local gitconfig would be needed for each of the cloned repos respective to the author of that repo. The advantage here, is that each developer's repo is their own.

0 Kudos
Message 2 of 13
(3,497 Views)

Hi, 

Thanks for your reply. This confirms the separate config files approach. 

 

So far there is some objection to the multiple clones on one PC, but I will press that idea. Then each of the repos would have its own .git/config file within the repo already with the --local user.name and --local user.email. 

 

In addition, I need to switch the the ssh key files. So if an additional task for the users is to fiddle with the .git/config file, Then I could add a task of pointing to, or copying their ssh files to the right place. Once there's a clear, manual procedure, then we'd automate it.

 

I did have a notion that we could possibly group and load everyone's ssh keys into the local ssh-agent, and then it would automatically pick the right set depending on who's name was embedded in the most recent commit in the local .git repo that is being pushed. If anyone cares to comment on that good or bad, it would be appreciated. Thanks again. -cc

 

 

0 Kudos
Message 3 of 13
(3,482 Views)
Solution
Accepted by DowNow_

@DowNow_ wrote:

In addition, I need to switch the the ssh key files. So if an additional task for the users is to fiddle with the .git/config file, Then I could add a task of pointing to, or copying their ssh files to the right place. Once there's a clear, manual procedure, then we'd automate it.


I'm not sure why you need a separate key for each developer. You could just use the one for your Windows 'user'. If I'm not mistaken, the SSH key is simply to validate the source and destination, regardless of the 'user' of Windows or your remote Git server.

 

If, however, you do need separate SSH keys, then you could potentially set up a .ssh/config file with separate Hosts. E.g.

*********

Host person1
Hostname bitbucket.org
IdentityFile ~/.ssh/person1privatekey

Host person2
Hostname bitbucket.org
IdentityFile ~/.ssh/person2privatekey

***********

If you are able to convince your team to follow the multiple repos approach, then each person would have to reset their repo's 'origin' to point to the equivalent of git@personX:<bitbucketId>:repo.git. (Basically, replace remote URL with the Host alias above. My example is for a bitbucket-based repo.) This action would be done only once.

 

You could certainly script this for a single-repo, multiple SSH keys approach, whereby the 'origin' alias is updated according to the developer using the repo. (E.g. git remote set-url origin <the above custom URL>). Then your SSH agent will know from .ssh/config which identity file to use.

 

Just out of curiosity, are you using any commercial git client (GitKraken, GitTower, etc.) on this Windows computer? If so, those tools may offer better alternatives.

Message 4 of 13
(3,465 Views)

Hi,

 

Oh I am so dumb. Of course the keys are for the interaction with the server. That's what the forum is for, people who need help. Thanks. 

 

For changing users I'm going to go with changing the global settings in ~/.gitconfig (C:\User\loginName\.gitconfig) because it is one file always in the same place. Just change these or use the shortcut idea you mentioned.

$ git config --global user.name "Blake, Bob"

$ git config -- global user.email bob.blake@corporation.com

 

And we'll just use one persons ssh keys. BTW, the keys are uploaded to Bitbucket under one person's account. Maybe that threw me off onto the track of everyone should use their own key to push. So in this case we'll leave one person's keys on the central development PC and just change the global user settings as needed.

 

We use Git Bash and SourceTree sort of together. Some use Tortoise Git and I think we could attach a hook script to that to make these changes each commit. If there's some unforeseen problems I will check out GitKraken, GitTower. We could use something like that here if it was free 🙂

cc

0 Kudos
Message 5 of 13
(3,449 Views)

 


@DowNow_ wrote:

That's what the forum is for, people who need help.


True that! Happy to be of assistance.

 


@DowNow_ wrote:

We use Git Bash and SourceTree sort of together. Some use Tortoise Git and I think we could attach a hook script to that to make these changes each commit. If there's some unforeseen problems I will check out GitKraken, GitTower. We could use something like that here if it was free 🙂


Hook script is a good idea!

 

I use GitKraken, mostly because I get to use the same tool for all desktop OSes. I like a couple of features in particular - one being the ability to set up different user profiles. It also interfaces with Jira, among other issue trackers, for me to access/update tasks directly in one desktop interface.

0 Kudos
Message 6 of 13
(3,393 Views)
Have you looked into using HTTP access tokens. They allow the bearer of the token access so the machine can be shared with multiple users. It is only available on Bitbucket server so if you are using bitbucket cloud I don't think it will work for you
0 Kudos
Message 7 of 13
(3,383 Views)

Hi,

 

Yes. I almost added that up front but trying to keep it brief. We do have Bitbucket server operated onsite somewhere. It is unreliable and there's very little support. I actually tried HTTP first, but ran into fatal errors on PCs behind an internal firewall. Crickets from support so I moved on to ssh. You are absolutely right. Thanks. -cc

0 Kudos
Message 8 of 13
(3,372 Views)

I had a similar situation once and just used a shell script to set the user in the git/config file.

Run a simple ./setuser.sh Me   Before going anything else. That worked.

Most of the git GUIs have support for this built in.

Sam Taggart
CLA, CPI, CTD, LabVIEW Champion
DQMH Trusted Advisor
Read about my thoughts on Software Development at sasworkshops.com/blog
GCentral
0 Kudos
Message 9 of 13
(3,304 Views)

Hi Sam that is great refinement. I'm stuck with quick and dirty at this time. What Git GUIs are you talking here? Sourcetree, TortoiseGit, what else? I know that TortoiseGit has a hook script attribute in its config. When you say "git/config" you mean the git config --local user properties with the repo itself. So the git app, GUI or Git Bash, will know the location of git/config because the user has pointed it to that repo. And then does ./setuser.sh prompt the user for their name and email? Thanks -cc

0 Kudos
Message 10 of 13
(3,274 Views)