DEV Community

Cover image for Creating and Managing Repositories on GitHub (With Git CLI Commands)
Ebelechukwu Lucy Okafor
Ebelechukwu Lucy Okafor

Posted on

Creating and Managing Repositories on GitHub (With Git CLI Commands)

If you have ever worked with code or followed a software project online, chances are you have come across GitHub. GitHub is a popular place for people to store code and work together on projects. The main thing that GitHub uses to organize all of this is something called a repository, or GitHub repository, which people often call a GitHub repo. A GitHub repository is a part of GitHub, and people use GitHub repositories to store their code and track changes to their code.

Knowing how repositories work is really important for developers and people who are just starting with version control.

They need to know how to manage them using GitHub and the command line.

This is a deal for developers, DevOps engineers and beginners who are learning version control with GitHub and the command line.

Repositories are a part of version control, and developers and beginners need to understand how they work with GitHub and the command line.

What Is a GitHub Repository?

A GitHub repository is like a place on the internet where you can store your project. This place has all your project files, like the code you write and the settings for your project. It also has things like a README file that tells people about your project. What is really cool about a GitHub repository is that it keeps track of every change you make to your files. It does this using something called Git, which is a system that helps you keep track of changes to your files. A GitHub repository is a tool because it uses Git to track these changes.

When you use Git, you can look at what changes were made, who actually made these changes and when these changes happened.

If something does not go as planned, you can easily go back to a previous version of Git.

Git repositories can be open for everyone to see. They can be private, which makes GitHub a good tool for open-source projects and for work that companies do privately with Git.

Creating a Repository on GitHub (Web Method)

To create a repository on GitHub:

Log in to your GitHub account.

Click the “+” icon at the top-right and select “New repository.”

Enter a repository name.

(Optional) Add a short description.

Choose Public or Private.

Check “Add a README file” (recommended).

Click “Create repository.”

When you make a repository on GitHub, GitHub gives you an address that you can use to link your computer to GitHub. This address is called the repository URL. You can use it to connect your local system to GitHub.

Creating a Repository Using Git CLI

A lot of developers like to use the command line. The command line is faster for them. It gives them more options. They can do things the way they want with the command line. The command line is really good, for developers because it is fast and it is flexible. Developers prefer the command line.

Step 1: Initialize Git in your project folder

git init

This command does something cool to your folder. It actually turns your folder into a Git repository. So now your folder is a Git repository.

Step 2. This is where you add your files to Git. You have to do this so that Git can keep track of the files. Add all the files you want to Git. This way, Git will know what files you are working with.

You are adding files to Git. This is a step. Make sure you add the files to Git.

To add all the files in the directory to git you should use the command git add.

This is what happens when you want Git to track all your files. It gets them ready, so Git can keep an eye on them. Git needs to track these files.

Step 3: Commit your changes

To start with, I will make my first git commit. The message for this git commit will be " commit". So the command for this git commit is git commit -m " commit". This git commit command is used to record the changes I made to my project.

When you make a commit, it saves a snapshot of your project at that moment. This snapshot is like a picture of your project. It shows exactly what your project looks like at that time. The commit saves this snapshot so you can look back at it later and see how your project was at that moment. This is really useful for keeping track of changes you make to your project over time. You can think of a commit as a way to save a copy of your project at a point in time.

Step 4: Connect your project to GitHub

To add a remote repository, you need to use the git remote add command. So you will do this by typing git remote add origin. Then you need to add the URL of your repository, which is https://github.com/username/repository-name.git.

So the full command is:

git remote add origin https://github.com/username/repository-name.git

Now we are at the step. This is Step 5. For Step 5 we need to push the code to GitHub. So the main task for GitHub, in Step 5 is to push the code to GitHub.

git branch -M main

git push -u origin main

Your local project is now uploaded to GitHub

How GitHub Repositories Work with Git

When you make a copy of a repository Git makes a copy of the project on your computer. This copy is the repository. The repository is what Git uses to keep track of the project. The project is stored in the repository. The repository is, like a folder that holds the project.

git clone https://github.com/username/repository-name.git

You can make changes to your work, on your computer then you can save these changes using commits. This way you can keep track of the changes you make to your work using commits.

git status

To add a file to git you need to use the command git add filename. When you type git add filename in the terminal you are telling git to add the filename file to the list of files that will be committed. The git add filename command is used to stage the filename file, which means it is preparing the filename file to be committed. You will use the git add filename command every time you want to add a file, such, as filename to your git repository. After you run git add filename you can then commit the filename file using the git commit command.

I just made a change, to the feature. I am going to save this with git commit and the message will be "Updated feature".

Finally, push your changes back to GitHub:

git push

This workflow is really helpful because it lets many people work on the project at the same time. The project workflow does this without letting people overwrite the work that other people have done on the project. This way the project workflow helps people to work together on the project.

Managing Files and Branches

When you are working on features branches are really helpful. They let you do this without messing up the code of the project. This way you can work on features and the main code at the same time and the main code will still work properly. Branches are very useful, for this reason.

Create a new branch

git branch feature-login

Switch to the branch

git checkout feature-login

(or)

git switch feature-login

After testing, merge it back into the main branch:

git checkout main

To combine the changes, from the feature login branch into the branch I will use the command git merge feature-login. This command will merge the feature-login branch into my branch. The feature-login branch contains all the new login features that I want to add to my project so I need to merge feature-login to get these features.

I will run the command git merge feature-login to do this. The git merge feature-login command is very important because it helps me to merge feature-login into my project.

Branches are really good for projects because they help keep everything organized. This way projects do not get all messy. Branches are very useful, for this purpose. They help people work on projects and keep them stable and organized which is what branches are supposed to do.

Collaboration Using Pull Requests

After pushing your branch to GitHub:

git push origin feature-login

You can open a Pull Request on GitHub. This is really helpful because your teammates can look at your code and tell you what they think. They can say what you should change. If it is good or not. This way, you can make sure your code is the best it can be. Pull Requests are a way to do this, and a lot of people use them for work and for open-source projects.

Useful Repository Management Tools

GitHub provides tools that make managing projects a lot easier. These tools help people work on projects together. GitHub has a lot of features that make project management easier. For example, GitHub has things like issue trackers and project boards that help people manage projects. GitHub is really useful for managing projects.

Issues Track bugs, tasks, and ideas

This is the README file for my project. It tells you what my project is about and what it does. My project is something I have been working on. I want to share it with you. The README file is where you can find all the information, about my project. It explains what my project does and how it works.

You need to control who can make changes to your code. This is about managing access to your code so you can decide who can edit it. Access control is important for your code. It helps you manage who can edit your code and who cannot.

I use GitHub Actions to automate things like testing and building my projects, and to make deployments easier. GitHub Actions is really helpful for automating these tasks. I do not have to do them manually every time. GitHub Actions automates testing. Deployments that save me a lot of time.

These tools are invaluable for your repository as it grows. Your repository can get really large. That is when these tools help it to keep going smoothly.

Creating and managing repositories on GitHub is a core skill in modern software development. Repositories help you store code, track changes, and collaborate efficiently. By learning both the GitHub interface and Git CLI commands, you gain full control over your projects. Whether you’re working alone or in a team, GitHub repositories form the foundation of effective version control and collaboration.

Top comments (0)