We have roughly 10 programmers this year, but we only have 5ish laptops. I’d like to have git or vscode prompt for a username and password every commit so we have a good way of seeing who does what.
Most forums online are solving the opposite problem of removing login prompts.
I have unset the git credential helper and removed the user.name and user.email from the global git config, but still have no luck.
Anyone know any tools or config settings that would create the desired behavior?
Based on this Stack Overflow answer, you can use the git -c user.name="<username>" -c user.email="<email>" commit -m "<message>" syntax to accomplish this.
Now, I’d personally hate having to type all of this out every time I wanted to commit so if you want, you could turn this into a bash/powershell/python/whatever kind of script that would take your students through a few prompts to make the process simpler.
Tbh I’d make a team programming account with access to the repos. If you use InteliJ you can have them each push one commit to the repository using their noreply git email Setting your commit email address - GitHub Docs
then have them select their username from the drop down everytime they commit.
can’t you just use user accounts for this? like in windows you’d create a “user” for each programmer, and windows would keep the git credential for each user.
I would have each student create a separate, personal, copy of the code to work on. Each checkout can include the git username in the checkout. Something like:
can you tell me more? our school does windows account management for the students, and so we’re in the process of moving from one-account-per-machine (where the students need to make sure they always use the same machine or else they’ll have the wrong git credential) to many-accounts-per-machine (so that, in theory, they could share machines). what’s the bad part?
This is not true for the vast majority of teams. Very few teams have the time, expertise, or funds to set up a Windows domain, and many laptops run Windows Home or equivalent. That means setting up individual accounts requires manual replication and maintenance across all the laptops.
If the computers are connected to a Domain (or similar login system), then actually maintaining the accounts is not a big deal. And then, yes, each user would use their account with their own copy of the git repo. When they push to the online repo (Github/Gitlab), presumably their credentials are stored and all is good. This would essentially be the same as how a company would operate.
The challenges I see come when things are not “normal”:
if a student works on code, and does not push at the end of the day, there might be changes are stuck waiting until that student comes in and pushes. So you might need to repeat work, or break into their account, or?
if you are at a competition, the machine will be disconnected from the account system. Most will cache accounts and credentials, but you better make sure that is up to date and all accounts you want to use are ready.
One other (possible) side issue: usually being part of Domain means you are also part of all the other systems that the IT department uses. So you may have to deal with firewalls, anti-virus, port blocking, etc which cause headache, especially for a Drive computer.
To the OP, if the goal is to get commits tagged with the author, then you could use a VSCode plugin like “git config user profiles” or similar. This adds a quick way to change config.user and config.email.
The problem I have had with these is that, yes, it changes the commit info, but it does not change/control the GitHub credentials. So “git push” ends up using the credentials of whomever put in their credentials (often me). So it does not work if you are trying to carefully control access to the Github repo.
I have 3 different git accounts on a single laptop, with one windows user, using ssh keys.
Setup is fairly straightforward, but time consuming. 10 programmers, all having access to the 5 laptops is 50 ssh key generations. I believe it’s possible to copy the keys over to another machine, but that would be ill-advised.
After setup, I can have all 3 of my git accounts with their own instance of VSCode to the same shared repo.
yes i agree with this, you should have each student use the windows version of ./sh script or alias in order to be able to just type "luke commit “message” and then it will automatically do the git command for them. i think this would probably be the easiest approach
and just forward all other command line arguments to actual git inside of those, but prefix with the right name/email?
Please don’t actually do this.
Edit… just realized this was Mochatitan’s actual suggestion I think.
I’m not entirely sure this actually solves the access issue though, still gotta have a common SSH key that works from a common account.
Of note we’ve been rockin with just generic PC accounts. So far no one’s cared about the fact the commit has the name of the PC they were using to do it, not their actual name. But if you wanted to be able to report per-student metrics on commits or something like that… yea that might not work.
For anyone interested we are going to try the onlyutkarsh.git-config-user-profiles VSCode Extension as @prensing suggested above. We created a generic software-student GitHub account that had all the same push/pull permissions as the students personal accounts. We will put an SSH key on all of our team laptops linked to that account. This way all the commits are authored by the student who did the work and the account that pushes to GitHub is hopefully hidden from them.
We are trying to teach the students good git and software development practices. I felt my degree program failed to teach this successfully and I was left to pick up these skills in internships. I wanted to give them a taste of these skills now to make them more valuable future interns.
We plan to test at our meeting this evening and I will report back if everything went as expected.
We were able to set up the extension and get it mostly working.
We have a team GitHub account that all our team laptops were logged in to, and we didn’t do anything with SSH keys to be able to commit as other users. This also seems to work well enough with GitHub desktop once you swap profiles in VScode.