DEV Community

Cover image for GitHub Basics: Creating Repository and Maintaining It

GitHub Basics: Creating Repository and Maintaining It

Table of content:

  1. Definition
  2. Requirements
  3. Creating a new Repository
  4. Maintaining a Repository
    • Fork the repository
    • Clone the repository
    • Create a branch
    • Initializing a repository
    • Adding files to the repository
    • Make an Initial Commit
    • Push changes to your repository
    • Pull requests
    • Renaming a repository
    • Transferring a repository
    • Deleting a repository
    • Restoring a deleted repository
  5. Conclusion

    1. Useful resources

Definition

GitHub is a web-based tool for version control and collaboration. It provides developers with an easy-to-use interface for creating repositories (remote storage sites), tracking code changes over time (version control), and collaborating on projects with others.

Requirements

  • GitHub Account
  • Git Installed
  • Text Editor or IDE
  • Basic Command Line Skills
  1. Creating a new repository

As a prerequisite you need a GitHub account to be able to create a repository.

Creating a GitHub account

  1. Navigate to https://github.com/.
  2. Click Sign up.
  3. Follow the prompts to create your personal account.

During sign up, you'll be asked to verify your email address. Without a verified email address, you won't be able to complete some basic GitHub tasks, such as creating a repository.
If you're having problems verifying your email address, there are some troubleshooting steps you can take. For more information, see "Verifying your email address."

Creating a new repository from the web UI
step 1-;
Once you have GitHub account, In the upper-right corner of your page, click the + sign .

Step 2-:
On the drop down list, click on the New repository option.

Step 3-;
Use the Owner drop-down menu to choose the account that will own the repository.

step 4-:
In the repository name field, enter a name for your repository and optionally provide a description. Select the desired repository visibility, then click the "Create repository" button at the bottom of the page.

For example-;

Step 5-;
At this point, you have successfully created a new repository using the web UI.

  1. Maintaining a Repository
  2. Fork the repository

Fork the repository by clicking the fork button on the top of the page. This will create an instance of that entire repository in your account.

  1. Clone the repository

To work with the repository locally, clone it to your machine. Click on the "Code" button and copy the provided link.

Open the terminal and run the following command. It will clone the repository locally.

$ git clone [HTTPS ADDRESS]
For example


$ git clone hhtps://github.com/ThanoshanMV/articles-of-the-week.git
Enter fullscreen mode Exit fullscreen mode

Now we have set up a copy of the master branch from the main online project repository.

$ cd [NAME OF REPOSITORY]
Enter fullscreen mode Exit fullscreen mode

  1. Create a branch

It’s good practice to create a new branch when working with repositories, whether it’s a small project or contributing to a group's work.
Branch name should be short and it should reflect the work we’re doing.
Now create a branch using the git checkout command:

$ git checkout -b [Branch Name]
Enter fullscreen mode Exit fullscreen mode

  1. Initializing a repository:

To initialize a new Git repository, open the terminal, navigate to the root directory of your project, and execute git init. This command initializes an empty Git
repository in the specified directory and generates a .git sub-directory that contains versioning information.

  1. Adding files to the repository

Make essential changes to the project and save it.
Then execute git status , and you’ll see the changes.
Use the git add . command to add your project files to the repository after it has been initialized. For instance, you may use git add . to add all files in the repository. The files are ready to be included in the subsequent commit at this point.

  1. Make an Initial Commit

Use the git commit -m "Initial commit message" command to generate an initial commit once you have added the required files. Commits are a snapshot of the project at a particular moment in time and ought to have a detailed message detailing the modifications that were made.

  1. Push changes to your repository

In order to push the changes to GitHub, we need to identify the remote’s name.

$ git remote
Enter fullscreen mode Exit fullscreen mode

remote

For this repository the remote’s name is “origin”.
After identifying the remote’s name we can safely push those changes to GitHub.

  1. On GitHub.com, navigate to the main page of the repository.
  2. Above the list of files, click Code.
  3. To clone your repository using the command line using HTTPS, under "Quick setup", copy link . To clone the repository using an SSH key, including a certificate issued by your organization's SSH certificate authority, click SSH, then copy link .
  4. Open Terminal .
  5. Change the current working directory to the location where you want the cloned directory.

git push origin [Branch Name]
Enter fullscreen mode Exit fullscreen mode
  1. Pull requests

To create a pull request that is ready for review, click Create Pull Request. To create a draft pull request, use the drop-down and select Create Draft Pull Request, then click Draft Pull Request.

  1. Renaming a repository
  2. On GitHub.com, navigate to the main page of the repository.
  3. Under your repository name, click Settings. If you cannot see the "Settings" tab, select the drop-down menu, then click Settings.
- In the Repository Name field, type the new name of your repository.
Enter fullscreen mode Exit fullscreen mode

Click Rename.
Enter fullscreen mode Exit fullscreen mode
  • Warning: If you create a new repository under your account in the future, do not reuse the original name of the renamed repository. If you do, redirects to the renamed repository will no longer work.
  • Transferring a repository
  • When you transfer a repository that you own to another personal account, the new owner will receive a confirmation email. The confirmation email includes instructions for accepting the transfer. If the new owner doesn't accept the transfer within one day, the invitation will expire.
    1. On GitHub.com, navigate to the main page of the repository.
    2. Under your repository name, click Settings. If you cannot see the "Settings" tab, select the drop down menu, then click Settings.
1. At the bottom of the page, in the "Danger Zone" section, click Transfer.
Enter fullscreen mode Exit fullscreen mode

  1. Read the information about transferring a repository, then under "New owner", choose how to specify the new owner.

        - To choose one of your organizations, select “Select one of my organizations.”
    
            - Select the drop-down menu and click an organization.
            - Optionally, in the "Repository name" field, type a new name for the repository.
            - Note: You must be an owner of the target organization to rename the repository.
    
        - To specify an organization or username, select Specify an organization or username, then type the organization name or the new owner's username.
    
  2. Read the warnings about potential loss of features depending on the new owner's GitHub subscription.

  3. Following “Type Repository Name to confirm”, type the name of the repository you'd like to transfer, then click I understand, transfer this repository.

  4. Deleting a repository

  5. On GitHub.com, navigate to the main page of the repository.

  6. Under your repository name, click Settings. If you cannot see the "Settings" tab, select the drop-down menu, then click Settings.

- On the "General" settings page (which is selected by default), scroll down to the "Danger Zone" section and click Delete this repository.
- Click I want to delete this repository.
- Read the warnings and click I have read and understand these effects.
- To verify that you're deleting the correct repository, in the text box, type the name of the repository you want to delete.
- Click Delete this repository.
Enter fullscreen mode Exit fullscreen mode
  1. Restoring a deleted repository

Some deleted repositories can be restored within 90 days of deletion.

  1. In the upper-right corner of any page, click your profile photo, then click Settings.

  2. In the "Code planning, and automation" section of the sidebar, click Repositories.

  3. Under "Repositories", click Deleted repositories.
    Next to the repository you want to restore, click Restore.
    Read the warning, then click I understand, restore this repository.

  1. Conclusion

Repositories on GitHub are an effective tool for organizing and working together on software projects. Developers may assure project transparency and version control, promote teamwork, and expedite workflows by adhering to best practices when creating, organizing, and managing repositories. Leveraging GitHub repository capabilities can greatly improve code quality and efficiency, whether working on a team project or a personal one.

  1. Useful Resources

Official GitHub Documentation

Git and GitHub Learning Resources

Tutorials and Guides

Books

Community and Forums

Top comments (3)

Collapse
 
james_otondi_056f064f6223 profile image
James Otondi

This the best article so far i have read. To whoever who worked on this thank you

Collapse
 
kasambx profile image
Kasamba Lumwagi

Wow! so insightful.

Collapse
 
denis_87 profile image
DENNIS NDERITU

Great article!