Home > Software design >  How to Change Git Configuration on EC2/CodeCommit
How to Change Git Configuration on EC2/CodeCommit

Time:01-26

I had an employee with IAM CodeCommit perms setup to push/pull in a project directory (and globally) on an EC2. However, that person was terminated and we had to disable the IAM user (big lesson there going forward). Now, I need to create a new ad-hoc IAM user and update the existing git config/credentials/remote. It's not working and I know I'm missing something but after much searching, I'm finding only how to set this up initially (after cloning the project) - not for changing an existing one and this doesn't address my situation.

This is what I've done so far. I created a new generic, ad-hoc user according to the instructions here: https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-gc.html.

I followed that with the exception of cloning the repo (that was already cloned under the previous user) and I changed the git config (got that - user.name and user.email are updated). But the credentials and remote url are not set for some reason and I am trying to set those so I can pull. Starting with the remote url here's what I'm getting:

git config --get remote.origin.url

(returns nothing)

So I try to add it:

git remote set-url origin https://git-codecommit.us-west-2.amazonaws.com/v1/repos/my-repo

But I get this:

fatal: No such remote 'origin'

And so, I drop the origin:

git remote set-url https://git-codecommit.us-west-2.amazonaws.com/v1/repos/my-repo

Then I get this:

`usage: git remote set-url [--push] [] or: git remote set-url --add or: git remote set-url --delete

--push                manipulate push URLs
--add                 add URL
--delete              delete URLs`

I think I'm on to something - so I modify and try to use --add:

git remote set-url --add my-repo https://git-codecommit.us-west-2.amazonaws.com/v1/repos/my-repo

I get this: fatal: No such remote 'my-repo'

I haven't gotten to the creds piece because in my tests, adding the url comes before I get prompted for creds anyway. Any suggestions helpful.

CodePudding user response:

I did not get why you would not just clone the repo from Amazon, that's probably the easiest solution to this but you might also try to add it as your new origin:

git remote set-url --add origin ssh://git-codecommit.us-west-2.amazonaws.com/v1/repos/my-repo

if my-repo actually exists as a repo there and you have set up ssh keys. If you prefer https instead, then documentation is at https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-https-windows.html

CodePudding user response:

I found an answer that worked for me - maybe this will help someone else. Here's what I did..

First, I had already added the user.name and email, but I'll put that here anyway:

git config --global user.name="deploy user" git config --global user.email="[email protected]"

Then, I setup the new deployment user I created on the EC2:

aws configure

After the prompts, I supplied the key, secret, and region.

Then, I navigated to the project directory and added new config info:

git remote add origin https://git-codecommit.us-west-2.amazonaws.com/v1/repos/my-repo git config --global credential.helper '!aws codecommit credential-helper $@' git config --global credential.UseHttpPath true

Checked to make sure it was setup properly with git config --global --edit

After this I was able to pull the changes without hitch. Hope this helps someone.

  • Related