Getting Started with Git and GitHub: Your First Repository

mdshamsfiroz
4 min readOct 28, 2024

--

In this blog post, we’ll walk through the process of creating a new Git repository, adding a file, committing changes, and pushing them to GitHub. This is a fundamental workflow that every developer should be familiar with. Let’s dive in!

Step 1: Create a New Folder
First, let’s create a new folder for our project. Open your terminal and run:

mkdir my-first-repo
cd my-first-repo

This creates a new directory called “my-first-repo” and navigates into it.
Step 2: Initialize the Git Repository
Now, let’s turn this folder into a Git repository:

git init

You should see a message saying “Initialized empty Git repository in [your folder path]”.
Step 3: Add a File
Let’s create a simple text file:

echo "Hello, Git and GitHub!" > hello.txt

This creates a file named “hello.txt” with the content “Hello, Git and GitHub!”.
Step 4: Stage the File
We need to tell Git that we want to include this file in our next commit:

git add hello.txt

Step 5: Commit the Changes
Now, let’s commit our changes with a meaningful message:

git commit -m "Initial commit: Add hello.txt file"

This creates a new commit with the message “Initial commit: Add hello.txt file”.

Step 6: Create a New GitHub Repository

  1. Go to GitHub.com and log in to your account.

2. Click the “+” icon in the top-right corner and select “New repository”.

3. Name your repository “my-first-repo”.

4. Leave the repository as public and don’t initialize it with any files.

5. Click “Create repository”.

Step 7: Link Local Repository to GitHub

GitHub will show you commands to push an existing repository. Copy and run these commands:

git remote add origin https://github.com/your-username/my-first-repo.git
git branch -M main
git push -u origin main

Replace “your-username” with your actual GitHub username.
Step 8: Verify the PushGo to your GitHub repository page and refresh. You should now see your “hello.txt” file in the repository.

Conclusion

Congratulations! You’ve successfully created a Git repository, made your first commit, and pushed it to GitHub. This workflow forms the foundation of version control and collaboration in software development.
Remember:

  • git init initializes a new Git repository
  • git add stages changes
  • git commit creates a new commit with staged changes
  • git push sends your commits to a remote repository

As you continue your journey with Git and GitHub, you’ll discover more advanced features and workflows. However mastering these basics is the first step towards becoming proficient in version control.

So, whether you’re a tech enthusiast, a professional, or just someone who wants to learn more, I invite you to follow me on this journey. Subscribe to my blog and follow me on social media to stay in the loop and never miss a post.

Together, let’s explore the exciting world of technology and all it offers. I can’t wait to connect with you!”

Connect me on Social Media: https://linktr.ee/mdshamsfiroz

Happy coding! Happy learning!

--

--

mdshamsfiroz
mdshamsfiroz

Written by mdshamsfiroz

Trying to learn tool by putting heart inside to make something

No responses yet