GIT Basics - A Primer on GIT Administration and AWS CodeCommit

A detailed guide on GIT basics, covering everything from the creation of a GIT repository to basic GIT administration. It includes a step-by-step setup of an AWS CodeCommit repository and instructions on how to work with it using GIT.
Create a repo in AWS CodeCommit #
Since I started in GIT I always worked with remote repositories (Repo's) and I alway create the repo online first and the replicate it to my local machine. This is also what I will do now.
So, before we start it all we will need a remote GIT-repo, for this example AWS CodeCommit is used.
To create the repository on the CLI use the command as listed:
aws codecommit create-repository --repository-name MyDemoRepo --repository-description "My demonstration repository" --tags Team=NLU
This results in JSON output where we will need the following information in a later step.
{
"repositoryMetadata": {
"accountId": "123456733",
"repositoryId": "47f32799-ad70-4f23-a02f-84f0bffe6342",
"repositoryName": "DemoRepo",
"repositoryDescription": "My demonstration repository",
"lastModifiedDate": "2022-08-03T18:46:48.190000+02:00",
"creationDate": "2022-08-03T18:46:48.190000+02:00",
"cloneUrlHttp": "https://git-codecommit.eu-west-1.amazonaws.com/v1/repos/DemoRepo",
"cloneUrlSsh": "ssh://git-codecommit.eu-west-1.amazonaws.com/v1/repos/DemoRepo",
"Arn": "arn:aws:codecommit:eu-west-1:123456733:DemoRepo"
}
}
Getting started #
- Create a project folder and move into it
This will be the local folder where the code is saved.
mkdir [project] && cd [project]
- Initiate GIT
Now it is time to nest out remote repo to our local machine:
git clone <https://git-codecommit.eu-west-1.amazonaws.com/v1/repos/DemoRepo> .
git status
If you included the final "." the repo will be created in the local folder, otherwise a folder will be create with the name of the repo and you will need to "cd" into that folder.
You will be warned: "You appear to have cloned an empty repository" but that is exactly what we just did on purpose.
Now we are ready for coding!!!
-
Adding a .gitignore
Git creates a main branch once you've done your first commit. There's nothing to have a branch for if there's no code or files in the repository. So first we will add a .gitignore file so that there is at least something in our repo.
For the working and purpose of .gitignore click here
Example .gitignore for React-App
After we created the first file for our repository, we can do the initial commit. This is a 3-step manouvre: first we need to add the file to the repo an then we need to commit it and finally we sent it to the online repo.
git add .
git commit -m "Initial commit"
git push
-
Setting up a new branch and work in it
Not often we want to work in the main branch so we nee to set up out own branch and change into this. This means that commits will be sent to your own branch. For this to happen you need to set up your own branch, connect to it an replicate this to the remote repository.
git branch [new-branch]
git checkout [new-branch]
If we want to add code to the remote-repository/new-branch we can simply GIT-add and GIT-commit locally but if we want to push it to the remote-repository/new-branch we need to push it with the following command:
git push --set-upstream origin new-branch
-
Merging the new-branch with main
If you are done coding in the new-branch and ready to add your code back to the main branch. You should switch back to the main branch and the merge the new-branch with the main branch.
git checkout main
git merge new-branch
-
Delete the branch
once we are done with the branch we can actually delete it.
git branch -d new-branch
git push origin --delete new-branch
Conclusion #
As you have seen AWS CodeCommit is simply just another GIT service the only thing we have don AWS wise is creating the repo and from there it is all GIT as GIT is.