MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

AWS Tutorials: Working with Code Commit

AWS CodeCommit is a managed, private Git hosting service. You create a repository in a Region, sign in with IAM-based credentials, and then use normal Git commands to clone, commit, push and open pull requests. This page goes with the console walkthrough above: it adds the IAM permissions you need, the three ways to authenticate, a corrected command sequence, pull requests from the AWS CLI and fixes for the most common errors.

Prerequisite – Make Sure you have CodeCommit IAM Access

IAM Add permissions page attaching AWSCodeCommitFullAccess policy to the airbusgroup user group

Step 1 – Create a Git Repo

AWS CodeCommit Repositories list with the Create repository button highlighted

Step 2 – Get a Git repo Access

Get a repo access Key for HTTPS or Upload you public key for SSH in IAM

AWS IAM user summary page with Users menu and Security credentials tab highlighted
IAM security credentials showing SSH public keys and HTTPS Git credentials sections for AWS CodeCommit

Step 2 – Code commit/push/pull request


git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/rajesh
git config user.name "Rajesh Kumar"
git config user.email "rajesh@devopsschool.com"
git add .
git commit -m:adding first"
git commit -m"adding first"
git push origin master
git branch dev
git checkout dev
clear
touch dev.txt;git add .;git commit -m"adding commit"
git push origin dev
Code language: PHP (php)

Verify at code CodeCommit

AWS CodeCommit repository rajesh on master branch listing dev.txt and raj1.java files

Before you start: IAM permissions and service status

The prerequisite above says you need CodeCommit IAM access. In practice, attach one of the AWS managed policies to the IAM user or group that will use Git, or write a narrower custom policy.

Managed policyWhat it allowsTypical user
AWSCodeCommitReadOnlyBrowse repositories and run git pull/cloneAuditors, CI jobs that only read
AWSCodeCommitPowerUserEverything except deleting repositoriesDevelopers
AWSCodeCommitFullAccessFull control, including deleting repositoriesAdministrators

For least privilege, Git operations only need codecommit:GitPull and codecommit:GitPush on the repository ARN:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["codecommit:GitPull", "codecommit:GitPush"],
      "Resource": "arn:aws:codecommit:us-east-1:111122223333:rajesh"
    }
  ]
}Code language: JSON / JSON with Comments (json)

Note: Use an IAM user or a federated role, not the root user. HTTPS Git credentials and SSH keys for CodeCommit are tied to IAM users. AWS also stopped accepting new CodeCommit customers in July 2024 and later announced it was reversing that decision. Check the current CodeCommit documentation to confirm the service is open to your account before you build on it.

Create the repository from the AWS CLI

Step 1 above uses the console. The CLI does the same thing in one command and returns both clone URLs:

aws codecommit create-repository \
  --repository-name rajesh \
  --repository-description "Demo repo for CodeCommit tutorial" \
  --region us-east-1Code language: JavaScript (javascript)
{
  "repositoryMetadata": {
    "repositoryName": "rajesh",
    "cloneUrlHttp": "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/rajesh",
    "cloneUrlSsh": "ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/rajesh",
    "Arn": "arn:aws:codecommit:us-east-1:111122223333:rajesh",
    ...
  }
}Code language: JavaScript (javascript)

Choose an authentication method

Step 2 above mentions HTTPS keys and SSH keys. There are three supported options. Pick one per machine.

MethodHow it worksBest for
HTTPS Git credentialsIAM generates a static username and password for the userQuick start, IDEs, Windows
SSH keyUpload a public key to IAM and use the returned SSH key IDDevelopers already using SSH
git-remote-codecommitGit helper that signs requests with your AWS CLI profile, SSO or role credentialsFederated users, temporary credentials, multi-account setups

HTTPS Git credentials: go to IAM > Users > your user > Security credentials > HTTPS Git credentials for AWS CodeCommit > Generate credentials. Download the file, because the password is shown only once. An IAM user can have at most two sets. Git asks for these credentials the first time you clone or push.

SSH: generate a key, upload the public part on the same IAM page (SSH public keys for AWS CodeCommit), and copy the SSH key ID, which starts with APKA. Then add an SSH config entry:

ssh-keygen -t rsa -b 4096 -f ~/.ssh/codecommit_rsa

# ~/.ssh/config
Host git-codecommit.*.amazonaws.com
  User APKAEIBAERJR2EXAMPLE
  IdentityFile ~/.ssh/codecommit_rsa

# test (expect a 'successfully authenticated' message)
ssh git-codecommit.us-east-1.amazonaws.comCode language: PHP (php)

git-remote-codecommit: this needs no IAM user secrets. It reuses whatever the AWS CLI is configured with:

pip install git-remote-codecommit
# format: codecommit::REGION://PROFILE@REPOSITORY
git clone codecommit::us-east-1://default@rajeshCode language: PHP (php)

Corrected clone, commit and push sequence

The command block above includes a broken commit command, assumes a master branch that may not exist, and tries to commit to an empty repository without creating a file first. Here is a working version with comments:

# clone (an empty repo prints: 'You appear to have cloned an empty repository.')
git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/rajesh
cd rajesh

# identity for commits in this repo (add --global to set it for all repos)
git config user.name "Rajesh Kumar"
git config user.email "rajesh@devopsschool.com"

# create content: an empty repo has nothing to commit
echo "# rajesh" > README.md
git add .
git commit -m "adding first"

# give the branch an explicit name, then push and set upstream
git branch -M main
git push -u origin main

# feature branch
git switch -c dev            # same as: git branch dev && git checkout dev
touch dev.txt
git add dev.txt
git commit -m "adding dev.txt"
git push -u origin devCode language: PHP (php)
  • git branch -M main renames the current branch. This keeps the push from depending on the machine's init.defaultBranch setting. If you prefer master, use that name throughout.
  • -u sets the upstream, so later git push and git pull work without arguments.
  • The first branch you push becomes the repository's default branch in CodeCommit. You can change it with aws codecommit update-default-branch.
  • git switch -c is the modern equivalent of git branch followed by git checkout.

Create and merge a pull request

The original heading mentions pull requests but does not create one. You can open one in the console (Repositories > rajesh > Pull requests > Create pull request) or from the CLI:

aws codecommit create-pull-request \
  --title "Add dev.txt" \
  --description "First feature branch" \
  --targets repositoryName=rajesh,sourceReference=dev,destinationReference=main

aws codecommit list-pull-requests --repository-name rajesh --pull-request-status OPEN

# merge (replace 1 with the pullRequestId returned above)
aws codecommit merge-pull-request-by-fast-forward \
  --pull-request-id 1 --repository-name rajesh

# update your local main
git switch main && git pullCode language: PHP (php)

Fast-forward works only when main has not moved since dev branched from it. Otherwise, use merge-pull-request-by-squash or merge-pull-request-by-three-way, or merge in the console. For more on branching strategy, see the Git Workflow Master Tutorial.

Common errors and fixes

ErrorLikely causeFix
fatal: unable to access ... The requested URL returned error: 403Wrong Git credentials, credentials cached for another user, or no GitPush/GitPull permissionCheck the IAM policy. Clear old entries in macOS Keychain or Windows Credential Manager for git-codecommit.*
error: src refspec master does not match anyNo commit yet, or the local branch is called mainCommit a file first. Check the branch name with git branch and push that name
Permission denied (publickey)SSH config User is set to the IAM user name instead of the SSH key ID, or the key is inactiveSet User to the APKA... key ID and confirm the key is Active in IAM
dquote> or > prompt after git commitUnmatched quote, as in -m:adding first"Press Ctrl+C and rerun with -m "message"
Pushes fail intermittently on macOS using aws codecommit credential-helperKeychain caches the short-lived password the helper generatesRemove the cached Keychain entry, or switch to git-remote-codecommit

Best practices

  • Use git-remote-codecommit with IAM Identity Center or role-based profiles instead of long-lived HTTPS Git credentials. See AWS Identity Center Guide.
  • Protect main with an IAM policy that denies codecommit:GitPush and codecommit:MergeBranchesBy* when the codecommit:References condition matches refs/heads/main. Require pull requests instead.
  • Use approval rule templates to require a minimum number of reviewers before a pull request can merge.
  • Never commit secrets. Add a .gitignore before the first commit.
  • If your builds run in private subnets, use the CodeCommit interface VPC endpoints so Git traffic stays inside AWS.

Frequently asked questions

Can I use the AWS root user with CodeCommit?

No, not for Git access. Create an IAM user or use federated access, then generate HTTPS Git credentials, upload an SSH key or use git-remote-codecommit.

What is the difference between HTTPS Git credentials and git-remote-codecommit?

HTTPS Git credentials are a static username and password generated for an IAM user. git-remote-codecommit signs each request with your AWS CLI credentials, so it works with roles, SSO and temporary credentials and leaves no static secret on the machine.

Why does my SSH clone fail when my IAM user name is in ~/.ssh/config?

CodeCommit expects the SSH key ID that IAM shows after you upload the public key, which starts with APKA. It does not accept the IAM user name. Put that ID in the User line of the SSH config.

Is AWS CodeCommit still available?

AWS paused new-customer onboarding in July 2024 and later announced it was reversing that decision. Existing repositories kept working throughout. Check the current CodeCommit documentation to confirm availability for your account.

How do I change the default branch of a CodeCommit repository?

Run aws codecommit update-default-branch --repository-name rajesh --default-branch-name main, or change it in the repository settings in the console.

Related tutorials

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Git Lab Exercise & Assignment: Git cherry-pick: Part – 12

git cherry-pick copies one or more existing commits from another branch and applies them as new commits on your current branch. This lab corrects and completes the…

Read More

Git Lab Exercise & Assignment: Changing History with Amend: Part – 5

This lab covers three ways to rewrite local Git history: fixing the last commit with git commit –amend, reordering commits with git rebase -i, and undoing it…

Read More

How to Configure pre-commit for Terraform: Complete DevOps Guide with 15 Practical Use Cases, Commands, Security Checks, and Best Practices

Terraform pre-commit Hooks: Installation, Configuration, TFLint, Trivy, Checkov & CI/CD Guide Learn to configure pre-commit for Terraform with step-by-step commands, terraform fmt, validate, TFLint, Trivy, Checkov, terraform-docs,…

Read More

How to Install and Configure pre-commit on macOS, Windows, and Linux: Complete Step-by-Step Guide

SEO Title: How to Install and Configure pre-commit on Mac, Windows & Linux (2026) Meta Description: Learn how to install and configure pre-commit Git hooks on macOS,…

Read More

Git, GitHub, and GitLab Interview Questions: Practical Answers and Command Guide

A practical interview-prep guide covering core Git concepts, essential commands, and common GitHub/GitLab questions. Includes workflow diagrams, comparisons, and troubleshooting checklists.

Read More

Git Training Roadmap: Practical Curriculum, Labs, and Team Workflow

A modern, hands-on Git training blueprint for DevOps and engineering teams. Use this curriculum, workflow, and command labs to build real-world Git skills quickly.

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x