Working with Branches in CodeCommit

Working with branches

A branch is simply a folder or a separate place where a developer/collaborator can organize their work without affecting other works in the main repository. There is usually a default branch that serves as a central place where the latest changes are stored. This default branch is usually named the main branch, master branch, but can be any other name chosen by a development team.

Adding files to a repository

To quickly get started with CodeCommit, new files can be created right from the AWS CLI or uploaded using Git from a local computer.

Note: When a new repository is created, it is empty, and initial configurations need to be done. The fastest way to get the repository ready is by creating a new file from the console. The other option includes cloning the repository using an HTTPS/SSH connection, making changes, and then pushing the changes back to the repository.

Files can be added to a branch using the put-file command as shown below:

aws codecommit put-file --repository-name CICD_on_AWS --branch-name main --file-content file:///usercode/helloWorld.txt --file-path /helloWorld.txt --name "John Doe" --email ""

Note: A text file helloWorld.txt has been created in the path /usercode/ for your practice.

The required parameters include the following:

  • repository-name: This is the name of the repository.
  • branch-name: This is the name of the branch to add the file(s) to.
  • file-content: This is the file to add.
  • file-path: This is the path to place the file in the repository.
  • parent-commit-id: This is a unique commit ID for the commit.
  • name: This is the name to attach to the commit.
  • email: This is the email to attach to the commit.
  • commit-message: This is the commit message to attach to the commit.

View information about a specific branch

We can use the get-branch command to get information about a branch.

Get hands-on with 1200+ tech skills courses.