Hacker News new | past | comments | ask | show | jobs | submit login

You can also do a per-directory _global_ git configuration, e.g.

in .gitconfig, you say:

    [user]
        name = Me Myself
        email = personal@example.com
        signingkey = D34DB44F

    [includeIf "gitdir:~/src/github.com/work_org/"]
        path = ~/.gitconfig_work
Then in ~/.gitconfig_work:

    [user]
        name = Me Myself
        email = work@example.com
        signingkey = D34DC0D4
    
    [core]
        sshCommand = ssh -i ~/.ssh/work_ed25519
I like this way better, because I don't need to remember to specify per-project config, as long I put them in the right directory :-)



While this works great if you are using your personal computer to do work. But if you use your employer issued computer to do personal hobby project, then please be very careful. In 90%+ of the cases your contract with your employer have the claus saying (please review your contract to clarify) that they own copyright of all your work while you are under the contract even if it's outside of working hours or on the weekend, with a few exceptions, and using employer equipment (employer issued computer) nullify one of the biggest exceptions.

IANAL but I would strongly suggest everyone to only use their employer issued computer to do work related work and move all their personal, hobby projects into their own personal computer, unless you don't care your employer owning the copyright of your personal hobby projects.


Advice I’ve gotten: not on company property, or with company resources (equipment, networking, technology).

You want to work on your personal project before going home, bring your laptop to work with you, go to a coffee shop (off-property) and work there.

That said, when I’m doing PRs for open source, it gets a bit awkward to use my work ID. If I have permission to contribute to dependencies on work time (which has definitely not always been the case), then something like this could be useful.


My personal take on open source contribution: If this is related to your work, you are getting paid for working on the contribution by your employer, then your employer should get the credit, thus you should use your work email/id. Otherwise, treat it as your personal hobby project and don't use employer resource to work on it.


Only "should" here is whatever arrangement you agreed to with your employer.


I think that depends on whether you intend to walk away from those changes once you take a new job.

Contributing to OSS isn’t just about fixing a problem for my company. I could do that internally. It’s about fixing a problem for everybody, including future me.


Using your work email doesn't remove your name. Both you and your employer get the credit.


If you're not doing it on their time, property or equipment and you're not getting overtime, no you're not.


If all your ifs are met, then you are not getting paid for it, which is a criteria from my comment :) Also this whole discussion is about suggest against people from using employer equipment to do personal projects :)


Exactly, have a similar setup, I would recommend against using the approach suggested in the post if you want to be 100% sure of always using the right account.


This setup does ensure this. These are the two relevant commands: git config --global --unset user.email (etc.) git config --global user.useConfigOnly true

This means that there is no default email set, and that git will error if you try and commit, because there is no email set.

I do a lighter weight version of this article by just doing the above. Then when I do the first commit in a repo, I get that error and I do the following command:

git config --local user.email me@myworkemail.com

(or the my personal email as appropriate). Then I have per repo config that persists unless I blow the repo away completely.


The article guarantees that by:

- requiring a user to be set

- not having one filled in the global settings

The upside is that even if the folder is moved, the user config still applies. The downside is that you have to set it per repository (but only once).

There are pros and cons, but I don't see one being any better or worse than the other in absolute terms.


This is fantastic. I had no idea this was possible.


I came up with a similar setup recently, and it works great. Also lets you keep the main gitconfig in version control with my other dotfiles


Why do you need to use different name/key/email between work and personal project?


Well, the e-mail part is pretty straightforward, since many people will have a personal e-mail and a separate e-mail managed by their workplace IT.

If some current (or future) coworker has a question about the code, I don't want them to necessarily e-mail me on my home account. I might not be checking it during work hours, or I might not even be with the company anymore.

Similarly, if someone actually wants to contact my e-mail for a hobby-project, I don't want them to send it to my work-account, which over time I might no longer have access to anyway.


> Similarly, if someone actually wants to contact my e-mail for a hobby-project

Also, some people prefer to not disclose their employer on GitHub hobby projects (or at all on the web). Simiarly, your employer doesn't necessarily need to know about every hobby project you start (as long as you're not violating work-contract clauses).


This also applies to e.g CI systems, that are able to send build success/fails emails to the emails in the commits instead of the default GitHub/GitLab email.


Actually, both GitLab and GitHub allow configuring different email addresses per team.

The notifications don't go to the email in the git commit.


I have to do this too because I work for different client and every client have their own gitlab which they only give access to account with their corporate email. So i have to commit under myname@client1.com for client 1, my.name@client2.fr for client 2 and so on.

Since I usually have to work on several repositories, I usually do what OP presented. I have one directory per client with each their own configuration and their repositories.


I used to have the client per directory setup too. But then took it one step further.

Now for every client i set up a separate VMWare Workstation virtual machine with all the relevant git config files, ssh keys, software and build dependencies etc.

That way every client is compartmentalized and there is limited chance of data or code leaking between clients. And i can always mid-session put the VM on pause, switch to another client and then resume right where i left, with all the editor windows open and services running.

I call it the container approach to workspaces.


Sounds good. +1 for writing it up and sharing dets! :)


Sounds a bit like what Qubes does


In many workplaces, you're required to use the company provided email address with git. And the name some people use at work isn't the same as what they use in their personal projects. (For ex, I use my full name at work but a shorter one for personal stuff)


Can be a lot of reasons. Some people (like me) like to keep their personal identity and work identity separated. Also some company policies forces you to use a different SSH key/GPG key for work-related stuff.


Another (possibly simpler) approach is to set project specific settings in the `.git/config` file, right in the project directory. As for the OP's example, in:

`~/src/github.com/work_org/.git/config`

without modifying the root `~/.gitconfig` file.




Applications are open for YC Summer 2021

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: