GitHub Basics: Creating and Setting-up a Repository

GitHub Basics: Creating and Setting-up a Repository

Discover the essentials of GitHub, key Git commands and practical tips to manage and collaboration on coding projects effectively.

Introduction

If you are new to programming, GitHub is a must learn tool. It not only helps you manage your code but also makes collaboration effortless. If you’re working on a project, and suddenly you lose your track of changes made or need to collaborate with others, GitHub solves these challenges and many more.

In this blog, I’ll introduce you to GitHub and its basic functionalities, followed by some Git commands to help you initially and a practical example to get started with GitHub.

What is GitHub?

GitHub is a web-based platform built around Git, a distributed version control system created by Linus Torvalds.

GitHub is an online open-source platform for software development that allows users to create, store and collaboration codes and files. Here, by open-source platform it means GitHub makes its source code available for anyone to use, modify and redistribute.

Key Features of GitHub

  • Version Control: Track changes to your code over time.

  • Collaboration: Work with others through branches and pull requests.

  • Repositories: Store and organize project files.

  • Integration: Supports CI/CD, code reviews, and more.

How to Set Up GitHub?

  1. Create a GitHub account: If you don’t have a GitHub account create it here.

  2. Install Git: Download and install Git from its official website.

  3. Configure Git: Set your username and email in Git.

     git config --global user.name
     "Your Name"
     git config --global user.email
     "Your email id"
    

What are the Core Git Commands you need to know?

Some important GitHub commands are mentioned below:

  1. Initialize a Repository

    To create a new repository in your local terminal:

     git init
    
  2. Clone a Repository

    Copy any repository to your terminal:

     git clone <repository-url>
    
  3. Check Repository status

    View status of changes made to your locally setup repository:

     git status
    
  4. Add Files

    Add your files to the cloned repository:

     git add <file-name> #adds a specific selected file
     git add .           #Adds all changes you have commited to your code
    
  5. Commit Changes

    Save your changes to your repositories:

     git commit -m "any commit meassage"
    
  6. Push Changes

    Upload your commits to the remote repositories:

     git pull origin <branch>
    
  7. Pull Updates

    Merge updates from remote repositories:

     git pull origin <branch>
    

A Practical Example

Let’s create a simple file and push it to the GitHub repository:

  1. Create a new GitHub repository on GitHub:

    Go to your GitHub profile.

    Click new repository.

    Name it and choose visibility (public/private).

  2. Initialize the repository locally:

     git init
     git remote add origin <repository url>
    
  3. Add Files and Push:

git add .
git commit -m "Commit message"
git push -u origin main

Conclusion

GitHub combines the best of version control and collaboration into one platform. With these basics, you can move forward to contribute to open source projects or lead your own.

Feel free to share your feedback.

Happy Coding!