17

I have some cloudinit scripts to execute when my AWS EC2 Ubuntu instance starts up.

I want to setup GIT config variables, with the code below.

#cloud-config
runcmd:
- [ sh, -c, "git config --global user.name 'myname'"]

When logged into the terminal. I can execute git config --global user.name 'myname' with no problem.

However when I attempt to start my instance with the cloudinit code. I get an error message

fatal: $HOME not set

My understanding is this is because the HOME is not set when the instance starts up.

Looking for a solution, to get the git variable to be set on startup or an alternate solution.

user1811107
  • 729
  • 3
  • 18
  • 39

2 Answers2

29

I ran into the same problem...

git config --system http.sslVerify false
git config --system user.email "email@email.com"

This resolved the error message. I got this solution after reading CodeCommit with EC2 Role Credentials. The reason is stated in the blog... "But when I ran this as root, I ran into the error fatal: $HOME not set, because git config --global is trying to read/write the current user's $HOME/.gitconfig file, and root seems to be $HOME-less in this context.

After being thoroughly schooled in git settings management, I can tell you that there is another option -- to set the system-wide git preferences with git config --system, which results in modifications to /etc/gitconfig, no errors. "

P.S. I realize that I'm answering this question almost 3 years later, but I'm hoping that this might help others who face the same issue.

mohifleur
  • 315
  • 5
  • 10
  • 1
    I confirm, setting that context resolve above issue. Thanks! – rafal1337 Nov 21 '19 at 10:44
  • 1
    confirmed, changing to `git config --system ____` from `git config --global ____` in my user-data script fixed my problem – Robin Dec 17 '19 at 15:02
  • Using the sslVerify configuration, I got `error: could not lock config file /opt/etc/gitconfig: Read-only file system` error – user3382968 Jun 10 '21 at 07:08
2

I just used sudo and it resolved my problem

git config --global user.email "you@example.com" git config --global user.name "Your Name"

sudo git config --global user.email "you@example.com"
sudo git config --global user.name "Your Name"
Adnan Siddique
  • 324
  • 3
  • 9