Creating Your First GitHub Repository

3/24/20234 min read

Creating Your First GitHub Repository

Welcome to the third blog of the series! In the last blog, we saw how to set up Git on your local machine. Now we need a place where we can remotely host the repositories. That's where GitHub comes into the picture.

GitHub is a web-based hosting service for Git repositories that offers additional features like collaboration tools, issue tracking, and pull requests. In this blog post, we will guide you through the process of creating your first GitHub repository and introduce you to some of the basic Git concepts you'll need to know.

Step 1: Sign up for GitHub

Before you can create a repository on GitHub, you need to sign up for an account. Go to the GitHub homepage and click on the "Sign up" button in the top right corner. Fill in your details and choose a plan (the free plan is sufficient for most users).

Choose the free plan now. I'll be telling in the future blogs how you can get the Pro plan for absolutely free!

Step 2: Create a New Repository

Once you're signed in to GitHub, click on the "+" button in the top right corner and select "New repository" from the dropdown menu. You'll be prompted to give your repository a name and description. You can also choose whether your repository should be public or private. If you choose a private repository, only you and any collaborators you invite will be able to access it.

New repo

Step 3: Initialize Your Repository with Git

Now that you've created a repository on GitHub, you need to initialize it with Git on your local machine. Open a terminal or command prompt and navigate to the directory where you want to store your code. Then run the following command:

git init

This will create a new Git repository in your current directory.

Step 4: Add Your Files to Git

To add your files to Git, run the following command:

git add .

This will add all the files in your current directory to the Git staging area. If you only want to add specific files, you can specify their names instead of using the "." wildcard.

If you want to add a specific file to the staging area. You can mention the filename after the command.

git add filename.extension

Step 5: Commit Your Changes

Once you've added your files to the staging area, you need to commit your changes. A commit is a snapshot of your code at a particular point in time. To create a commit, run the following command:

git commit -m "Initial commit"

This will create a new commit with the message "Initial commit" that includes all the changes you added to the staging area.

Step 6: Connect Your Local Git Repository to Your GitHub Repository

Now that you've created a commit, you need to push your changes to your GitHub repository. To do this, you need to connect your local Git repository to your GitHub repository. Run the following command:

git remote add origin <repository URL>

Replace with the URL of your GitHub repository. You can find this URL on the GitHub repository page, under the "Clone or download" button.

Step 7: Push Your Changes to GitHub

Finally, you can push your changes to GitHub by running the following command:

git push -u origin master

This will push your changes to the "master" branch of your GitHub repository. The "-u" flag tells Git to remember the remote branch, so you can simply run "git push" in the future to push your changes.

Conclusion

Congratulations! You've just created your first GitHub repository and initialized it with Git. You've also learned some basic Git concepts like staging, committing, and pushing changes. With this foundation, you can start exploring more advanced Git features and collaborating with other developers on GitHub.

Do you know that there's a secret GitHub repository? Check out this blog.

https://pratikkale.in/blog/the-secret-github-repository

Thank you for reading and do let me know your thoughts in the comments!

Website | Twitter | LinkedIn | Instagram | Mail