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

Step 1 – Create a Git Repo

Step 2 – Get a Git repo Access
Get a repo access Key for HTTPS or Upload you public key for SSH in IAM


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

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 policy | What it allows | Typical user |
|---|---|---|
AWSCodeCommitReadOnly | Browse repositories and run git pull/clone | Auditors, CI jobs that only read |
AWSCodeCommitPowerUser | Everything except deleting repositories | Developers |
AWSCodeCommitFullAccess | Full control, including deleting repositories | Administrators |
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.
| Method | How it works | Best for |
|---|---|---|
| HTTPS Git credentials | IAM generates a static username and password for the user | Quick start, IDEs, Windows |
| SSH key | Upload a public key to IAM and use the returned SSH key ID | Developers already using SSH |
git-remote-codecommit | Git helper that signs requests with your AWS CLI profile, SSO or role credentials | Federated 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 mainrenames the current branch. This keeps the push from depending on the machine'sinit.defaultBranchsetting. If you prefermaster, use that name throughout.-usets the upstream, so latergit pushandgit pullwork 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 -cis the modern equivalent ofgit branchfollowed bygit 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
| Error | Likely cause | Fix |
|---|---|---|
fatal: unable to access ... The requested URL returned error: 403 | Wrong Git credentials, credentials cached for another user, or no GitPush/GitPull permission | Check the IAM policy. Clear old entries in macOS Keychain or Windows Credential Manager for git-codecommit.* |
error: src refspec master does not match any | No commit yet, or the local branch is called main | Commit 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 inactive | Set User to the APKA... key ID and confirm the key is Active in IAM |
dquote> or > prompt after git commit | Unmatched quote, as in -m:adding first" | Press Ctrl+C and rerun with -m "message" |
Pushes fail intermittently on macOS using aws codecommit credential-helper | Keychain caches the short-lived password the helper generates | Remove the cached Keychain entry, or switch to git-remote-codecommit |
Best practices
- Use
git-remote-codecommitwith IAM Identity Center or role-based profiles instead of long-lived HTTPS Git credentials. See AWS Identity Center Guide. - Protect
mainwith an IAM policy that deniescodecommit:GitPushandcodecommit:MergeBranchesBy*when thecodecommit:Referencescondition matchesrefs/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
.gitignorebefore 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
- Git Workflow Master Tutorial
- AWS Tutorials: AWS Identity Center Guide
- AWS Tutoriaols: A Comprehensive Guide to AWS VPC Endpoint Services
- More AWS tutorials
- More Git tutorials
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.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals