Resources     Blog  

  1. Home
  2. Git Tutorials
  3. How To Manage a Git Repository

How To Manage a Git Repository

Git is a vast open source network with a ton of stuff to learn. If you are new to Git and don’t quite know how to start, then view the steps below that cover how to manage a Git repository.

Managing a Git repository comes with several aspects. Create a project, add files, commit modifications and upload them in the remote repository at GitHub are all things you will need to know to be able to manage your Git repository.

Create and Manage a Git Repository

The first thing you need to do is generate an SSH key. GitHub has some very detailed instructions on how to do this for MAC OS, Windows and Linux systems. You must have at least one SSH public key to push your git repository to GitHub

Once you have generated the SSH key you need to add it through the GitHub interface.

Click on the Settings page for your account, then on the SSH and GPG Keys section. On that page, click the “New SSH key” button.

Click on the new ssh key button

After you have clicked on the New SSH key button a panel will appear in which you should then input a Title for the key and the private key itself. Once done, press the “Add SSH key” button.

Click on the add ssh key button

Once you have added the SSH key you are ready to open a new Terminal window on your computer.

You should create a new folder to develop and manage the repository. This can be done by using the following command:

user@user [~]# mkdir GIT

That command will create a folder named “GIT” in the current working directory. You can then access that folder with:

user@user [~/GIT]# git init
Initialized empty Git repository in /home/username/GIT/.git/

You should also create files and folders for your git repository. For example, to create a README file use the following command:

user@user [~/GIT]# touch README

That command will create an empty file named “README” in the Git repository folder.

That being said, this does not automatically add the file to the Git repository. You can compare the list of files in the actual Git repository and the list of current files you have created with this command:

user@user [~/GIT]# git status
On branch master

Initial commit

Untracked files:

(use “git add <file>…” to include in what will be committed)


nothing added to commit but untracked files present (use “git add” to track)

The above command shows that you have a file named “README” that is present in the folder, but is not added to Git repository. So now, you need to add the file to the Git repository index. Do this by using the following command:

user@user [~/GIT]# git add README

Now you can compare again the list of files in the actual Git repository and the list of current files you have created:

user@user [~/GIT]# git status
On branch master

Initial commit

Changes to be committed:
(use “git rm –cached <file>…” to unstage)

new file:   README

As you can see, the file is now added to the repository index and now you need to commit it.

By committing a file, you add it to the actual repository. Committing is used when you create new files or modify existing ones and want to “push” your changes to the repository.

You can commit the README file by using the following command:

user@user [~/GIT]# git commit -m ‘first commit’

[master (root-commit) e2a16e0] first commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README

where “-m ‘first commit'” is a comment that is left in the repository history. Using commits you can describe the changes that are made to the repository files. This will help you better understand and follow the development of your project over time.

Now, if you check the status of the Git repository, you will see there are no new changes to commit. Do that like this:

user@user [~/GIT]# git status

On branch master
nothing to commit, working directory clean

Remember, all of these changes were done to a local repository on your machine. If you want to push them to the remote Git repository that you have on GitHub, then you first need to add the repository on your machine with the following command:

user@user [~/GIT]# git remote add origin

Please remember to replace your_username and name_of_your_repo with your actual GitHub username and the name of your repository.

The command will “link” the two repositories, so any changes made to the local one can be pushed to the remote one at GitHub.

Finally, to push the changes to the GitHub repository you use this command:

user@user [~/GIT]# git push origin master

Counting objects: 3, done.
Writing objects: 100% (3/3), 207 bytes, done. Total 3 (delta 0),
reused 0 (delta 0) To * [new branch] master -> master

Now, if completed properly you can access the GitHub repository and see the README file there.

Author: Jeremy Holcombe

Growing up in Hawaii, Jeremy started his freelance writing career doing resumes, business plans, article writing, and everything in between. He now specializes in online marketing and content writing and is part of the Content Marketing Team at GreenGeeks.

Was this article helpful?

Related Articles

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.