I use git
from two computers.
I would like to:
~/.gitconfig
file on the two computers.user.name
on commits from one computer or the other.In short, I'd like to be able to have something like user.name = "Mic - #{Hostname}"
, with Hostname
being dynamically read.
Is there a way to achieve this?
The only other way I see would be to manually change the user.name
on each git repo I use on those 2 computers - but I don't find it clean.
Solution for those in this situation:
There seems to be no built-in solution as git does not auto-expand config parameters. So, following the advice below, I just issue the following command in my deploying script after importing a new (shared) ~/.gitconfig
:
git config --global user.name "Mic [`hostname`]"
That way, git name is always updated.
Depending on your config, you can also put that in your ~/.bashrc
or whatever ~/bash_profile
you use - although it looks a bit overkill.
To set your Git username, run the git config –global user.name command. You should specify both your first and last name but your username can be anything you want to attach to your commits. Your Git username does not need to be the same as your version control username, such as the one you use on GitHub.
One thing to note is that each user gets their own global Git config file. This can cause problems if you run a shell script with sudo command. If sudo is used in a script, the ~root/. gitconfig file will be used instead of the global git config file of the user running the script.
About Git usernamesYou can change the name that is associated with your Git commits using the git config command. The new name you set will be visible in any future commits you push to GitHub from the command line. If you'd like to keep your real name private, you can use any text as your Git username.
Do not store name in ~/.gitconfig
but in your ~/.bash_profile
set environment variables:
GIT_AUTHOR_NAME="Mic - $HOSTNAME"
GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
export GIT_AUTHOR_NAME GIT_COMMITTER_NAME
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With