AWS Code Commit with Git Basics - I

AWS Code Commit is a fully managed, secure, private Git repository service used to store, version, and collaborate on source code and other assets. It eliminates the need to host your own Git server and integrates tightly with AWS services.

Let's start with creating a code commit repository from the AWS Console:


Repository name is "book" and I am going to create a file from the console by the name called "facts.txt" with the below content.


Here is the commit message for the file.



Now, our file is ready.


Take a note at the "Reference" as "main" which shows the file is created under main branch.

No need to worry about the terms branch, commit and others. This series covers it.

Now, our file is ready. Consider the file under the "main" branch is the ONE VIEWED/USED by everyone.

Now, we have been asked to make changes to the file. Change the numbers from 8,848.86 to ~ 9,000 meters.

In real, no organization allows to make changed to file in the "Main" branch. So, we have create a new branch out of the main branch.

In Git, a branch is a lightweight, movable pointer to a commit that lets you work on features, fixes, or experiments independently from the main line of development. It’s like creating a parallel timeline for your code — you can make changes safely without affecting the main branch until you merge them back.


I can make the updates from the console by create a branch from the AWS console. But, I will showing how to create a branch, make updates and other activities using GIT CLI.

The Git CLI (Command Line Interface) is the most powerful way to interact with Git, allowing developers to perform every version‑control operation directly from the terminal — including repository management, branching, merging, and collaboration.

Download git cli from https://git-scm.com/install/ 

I also recommend to check https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-ssh-unixes.html on how to configure SSH - Password less authentication for interacting with Code Commit Repo.

I completed the above steps. Hence, I am walking directly to CLI.

First, I need to CLONE the repo from AWS Console using the command # git clone <REPO URL>

Repo URL can be fetched from the AWS Console.


Here are the five steps process which we are going to cover.

Clone command creates a copy of the entire repo to the local folder.

$ git branch : Shows the current branch you are in.

The main branch (formerly often called master) is the default, primary branch in a Git repository that holds the stable, production-ready code

I am creating a new branch (feature-change) using $ git checkout command:

And confirm that I am in the "feature-change" branch. So, that any changes to the file will be under "feature-change" branch.


Now, we have successfully cloned the remote repo, created a branch locally  and switched to the branch.

I made the changes to the file using "vi" editor.

git add (The Staging Area)
The git add command moves changes from your Working Directory (where you edit files) to a temporary holding area called the Staging Area (or "index").
  • Purpose: It allows you to select exactly which changes you want to include in your next snapshot. For example, if you modified five files but only want to save the changes for two of them right now, you would only "add" those two.
git commit (The Snapshot)
The git commit command takes everything currently in the Staging Area and records it as a permanent snapshot in your Local Repository.
The git push command is used to upload local repository content to remote repository.
After the file is updated, we proceed to add, commit.

$ git log --oneline will shows the changes happened to the file and the associated commit id.
A Git commit ID (or SHA-1 hash) is a unique 40-character hexadecimal string that serves as a permanent, immutable identifier for a specific snapshot of a repository. It tracks changes, enables exact version restoration, identifies contributors, and ensures code integrity by changing if any content or metadata is altered.
Now, we can see 2 commit ID. One if the original file and the top one is the commit id of my change. 
To see the difference between the commits use the below command.
Finally, I push my local change from "feature-change" branch to the remote repo (AWS)'s feature branch.

Let's verify the file is updated from the AWS Code Commit repo.

Looks look. But the file under "main" branch is the one which is actually used.
So, we need to merge the change from the feature branch to main branch. 
To do this, we create something called "PR - Pull Request".
Pull requests are proposals to merge code changes into a project. A pull request is GitHub's foundational collaboration feature, letting you discuss and review changes before merging them. This helps teams work together, catch issues early, and maintain code quality.
I am creating the PR from AWS console:

Take a look at the "Source" and "Destination", it shows we are merging the change from "feature-change" branch to "main" branch".
We can also, what really changed in the PR.

Finally, we merge the PR.

Once the PR is merged. Verify the file from the main branch. It must have the changes we made in the feature-change branch.

In the next series, We will discuss on reverting the change.







Comments

Popular posts from this blog

K8s - ETCD

Agentic AI - Series 3

Agentic AI - Series 4