S
S
spaceatmoon2022-03-14 11:35:57
git
spaceatmoon, 2022-03-14 11:35:57

Is it possible to force git to ask which user to commit as?

Actually the question is in the title. I have for different systems - Github, Gitlab, etc. different accounts, both work and personal. It is very tedious to control for each repository which user is installed and the error still happens. Commits sometimes fly away with the wrong authorship settings.

Is it possible to somehow set up a list of users and then git would ask under which user to commit changes?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Korotenko, 2022-03-14
@firedragon

Git Configuration
As you read briefly in Getting Started, you can specify Git configuration settings with the git config command. One of the first things you did was set up your name and email address:
$ git config --global user.name "John Doe"
$ git config --global user.email [email protected]xample.com
Now you'll learn a few of the more interesting options that you can set in this manner to customize your Git usage.
First, a quick review: Git uses a series of configuration files to determine non-default behavior that you may want. The first place Git looks for these values ​​is in the system-wide [path]/etc/gitconfig file, which contains settings that are applied to every user on the system and all of their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.
The next place Git looks is the ~/.gitconfig (or ~/.config/git/config) file, which is specific to each user. You can make Git read and write to this file by passing the --global option.
Finally, Git looks for configuration values ​​in the configuration file in the Git directory (.git/config) of whatever repository you're currently using. These values ​​are specific to that single repository, and represent passing the --local option to git config. If you don't specify which level you want to work with, this is the default.
Each of these “levels” (system, global, local) overwrites values ​​in the previous level, so values ​​in .git/config trump those in [path]/etc/gitconfig, for instance.

S
Stanislav Makarov, 2022-03-14
@Nipheris

I have for different systems - Github, Gitlab, etc. different accounts, both work and personal.

Might not be exactly what you want, GitKraken has profile functionality , a solution just right for your case. I use it for this - several "working" accounts with corporate mail in author / commit email, and a personal one. You need to switch in advance, before the commit (the global .gitconfig is simply updated).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question