Admittedly, I am –more or less– writing this article as a reminder to myself. I have created a few repositories on GitHub in previous years; however, I frequently forget the steps or encounter issues consistently. So, a deep dive into this topic is long overdue.
Install Git
If you do not already have Git installed on your machine, you must install it. You can download Git from the official website.
Log in to GitHub
If you do not already have an account, you must create one. Once you have an account, log in to GitHub.
Create a New Repository
Once you are logged in, click on the plus sign in the top right corner of the page. Then click on "New repository". This will redirect you to a new page, here you must fill out the following fields:
- Repository name: This is the name of your repository. It should be unique.
- Description: A brief description of your repository.
- Public or Private: Make your repository public or private, based on your needs.
- Initialize this repository with a README: leave this unchecked.
- Add .gitignore: Leave empty.
- Add a license: Leave empty.
- Create repository: Once you have filled out all the fields, click the green button to create your repository.
Note: Many tutorials do not mention that if you add files during creation, you cannot push files to the repository without errors (AKA knowing more about GIT than I do). You will need to clone the repository to your local machine, and then push the files to the repository. For this reason, I am leaving the README, .gitignore, and license fields empty. I add these files later if I need them. This will ensure that the following steps will work without errors.
Copy the Repository URL
Once you have created the repository, you will be redirected to the repository page. Copy the URL of the repository. You will need this to push your files to the repository. The URL should look something like this: git@github.com:user-name/repository-name.git
Push to Repository
Open a terminal and navigate to the directory where your project is located. Run the following commands:
git init
git add .
git commit -m "Initial commit"
git remote add origin [add repository URL here]
git push -u origin main
Note: If you use the SSH URL, you must have an SSH key created on your GitHub account.
Workflow for Subsequent Pushes
Once you have pushed the files to the repository, you can use the following command to push subsequent changes:
git add .
git commit -m "Commit message"
git push
There is more to GitHub than what I have covered in this article. This is just a quick start-up guide so you get to coding.
Thanks for reading!