How to Manage your GIT Repository Tutorial

Learn how to manage your GitHub repository

GIT Repository Management

This tutorial explains how to use GIT to create a project, add files, commit modifications and upload them in the remote repository at GitHub.

First, you should generate an SSH key. You must have at least one SSH public key to push your git repository to GitHub.

You can check our knowledgebase articles how to generate an SSH key in Windows, MAC OS and Linux.

Next, you should add the key through the GitHub interface. This is done by accessing the Settings page for your account -> SSH and GPG Keys section. On that page, click the New SSH key button.

A new panel will appear in which you should input a Title for the key and the private key itself. Once done, press the Add SSH key button.

Then, open a new Terminal window on your computer. First you should create a new folder in which to develop and manage the repository. This can be done with the following command:

This will create a folder named GIT in the current working directory. Access that folder with:

Then initialize a new GIT repository with:

You should create files and folders for your GIT repository. For example, you can create a README file with the following command:

This will create an empty file named README in the GIT repository folder. However this does not automatically add the file to the GIT repo. You can compare the list of files in the actual GIT repository and the list of current files you have created with:

The above 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. This can be done with:

Then, you can compare again the list of files in the actual GIT repository and the list of current files you have created:

The file is now added to the repo index and 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. To commit the README file, you can use the following command:

where "-m 'first commit'" is a comment which is left in the repository history. Using commits you can describe the changes which are made to the repository files, which will help you better to follow the development of your project.

Now,  if you check the status of the git repository, you will see there are no new changes to commit.

All of these changes were done to a local repository on your machine. If you want to push them to the remote GIT repo you have at GitHub, you first need to add the repo on your machine with:

Make sure 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.

To push the changes to the GitHub repository now, you can use this command:

Now, if you access the GitHub repository, you will see the README file there.