You can create a folder in an AWS CodeCommit repository by either creating a file within the desired folder path directly through the AWS Management Console or, more commonly, by pushing a commit via the Git command-line interface that includes files inside the new folder structure.
It's important to understand that Git, the version control system CodeCommit uses, does not track empty folders. To successfully create a folder, you must always place at least one file inside it.
Methods to Create a Folder in CodeCommit
There are two primary ways to achieve this:
1. Using the AWS CodeCommit Console
This method is convenient for quick additions or for users who prefer a graphical interface.
- Access the AWS CodeCommit Console: Navigate to the AWS CodeCommit dashboard in the AWS Management Console.
- Select Your Repository: Click on the name of the repository where you intend to create the folder. This action will take you directly to the 'Code' tab of that specific repository.
- Initiate File Creation: Locate the 'Add file' dropdown (or a similar button like 'Create file') typically found under your repository description. Click on it, then select 'Create file' from the options.
- Specify Folder and File Path: In the "File name" field, instead of just a file name, enter the full path including your desired folder name followed by a file name. For example, to create a folder named
my-project-assets
and place a file calledimage-list.txt
inside it, you would typemy-project-assets/image-list.txt
. - Add File Content: Provide some initial content for your file in the text area provided. Even a simple comment or placeholder text is sufficient.
- Commit Changes: Fill in the required fields for "Author name," "Email address," and a descriptive "Commit message" (e.g., "Added new 'my-project-assets' folder with initial file").
- Confirm: Click the "Commit changes" button. CodeCommit will then create the specified folder and place your new file within it.
2. Using the Git Command Line Interface (CLI)
This is the standard and most flexible method for developers working with Git repositories.
-
Clone Your Repository (if not already done):
If you don't have a local copy of your CodeCommit repository, clone it using:git clone <Your-CodeCommit-Repository-URL>
You can find your repository URL in the CodeCommit console under the 'Code' tab, by clicking 'Clone URL' and choosing your preferred protocol (HTTPS Git Credentials, HTTPS GRC, or SSH).
-
Navigate to Your Local Repository:
Change your directory to your cloned repository:cd <your-repository-name>
-
Create the Folder and a File Inside It:
Usemkdir
to create your folder andtouch
to create a dummy file inside it. A common practice is to create a.gitkeep
file (or.gitignore
) in an otherwise empty folder, which ensures the folder is tracked by Git.mkdir new-feature-docs touch new-feature-docs/initial-setup.md
Alternatively, you can just create any actual file you intend to put in that folder.
-
Add the New Folder/Files to Staging:
Stage the newly created folder and its contents for commit:git add new-feature-docs/
-
Commit Your Changes:
Commit the changes with a descriptive message:git commit -m "Add new 'new-feature-docs' folder with initial setup file"
-
Push to CodeCommit:
Push your local changes to your remote CodeCommit repository:git push origin main
(Replace
main
with your default branch name if it's different, e.g.,master
).
After pushing, you will see the new folder appear in your CodeCommit repository in the AWS Console.