This blog post is a simple cheat sheet how to create a new GitHub repository from a GitHub repository template, by not using the guide from GitHub.
In that case we use the template-terraform-gitops GitHub repository. That GitHub repository is a template to build own modules for terraform automations.
Step 1: Clone the project to your local computer
git clone https://github.com/cloud-native-toolkit/template-terraform-gitops
Step 2: Delete the .git
folder in the cloned project to disconnect the git repository
Step 3: Rename the root folder of the project from template-terraform-gitops
to gitops-terraform-guestbook
Step 4: Run the git init command in the gitops-terraform-guestbook
folder
That will create a new .git
folder.
git init
- Output
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /Users/thomassuedbroecker/Downloads/dev/gitops-terraform-guestbook/.git/
Step 4: Add .DS_Store to the .gitignore file (in case you are using MacOS)
.idea/
*.iml
terraform.tfstate
terraform.tfstate.backup
.terraform/
.DS_Store
Step 5: Execute the git add --all
command
git add --all
Step 6: Create new GitHub project gitops-terraform-guestbook
using git commit
git commit
- Interactive output:
It opens a vi editor
.
- Enter
I
- Now you can insert some text
Init repo
. - Press
esc
- Press
:
- Insert
wq
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
#
# Initial commit
#
# Changes to be committed:
# new file: .DS_Store
# new file: .github/.DS_Store
# new file: .github/release-drafter.yaml
# new file: .github/scripts/validate-deploy.sh
# new file: .github/scripts/validation-functions.sh
# new file: .github/workflows/manual-test-repo-delete.yaml
# new file: .github/workflows/notify.yaml
# new file: .github/workflows/publish-metadata.yaml
Step 7: Create a new empty GitHub repository with the name gitops-terraform-guestbook
That step needs to be done in the GitHub UI.
Step 8: Connect to the newly created GitHub repository
git branch -M main
USERNAME=YOUR_USERNAME
REPONAME=gitops-terraform-guestbook
git remote add origin git@github.com:$USERNAME/$REPONAME
Step 9: Push to the master
branch
If you don’t have a
ssh key
You can also visit may blog post Create a ssh key for your GitLab project on IBM Cloud to inspect how you create and use a ssh key in context with a GitHub repository.
git push -u origin main
I hope this was useful to you and let’s see what’s next?
Greetings,
Thomas
#github
Leave a Reply