Using Git and GitHub: A Step-by-Step Guide

Using Git and GitHub: A Step-by-Step Guide

A Helpful Guide for Using Git and GitHub

·

2 min read

Here's an easy-to-follow guide for using Git and GitHub:

Install GitHub CLI (gh):

  1. Open your terminal.

  2. Run the following command to install GitHub CLI:

     sudo apt install gh
    

Authenticate with GitHub:

  1. Run the command:

     gh auth login
    
  2. Follow the prompts to authenticate with GitHub.

Create a New Repository:

  1. Run the command:

     gh repo create <repo-name> --public
    

Initialize Git and Push to GitHub:

  1. If you haven't initialized Git yet:

     git init -b main
     git add .
     git commit -m "First commit"
    
  2. To push an existing local repository to GitHub:

     gh repo create
     # SELECT >> Push an existing local repository to GitHub
    
  3. Alternatively, if you want to create a new repository from scratch:

     gh repo create
     # SELECT >> Create a new repository on GitHub from scratch
     git add .
     git commit -m "Message"
    
  4. Push your changes to GitHub:

     git push -u -f origin main
    

Push Existing Project to an Existing Repository:

  1. Initialize Git (if not already done):

     git init -b main
    
  2. Add files, commit changes, and set up the remote repository:

     git add .
     git commit -m "hello my friend"
     git remote add origin <repository-url>
    
  3. Push your changes to GitHub:

     git push -u -f origin main
    

This guide should help you navigate through setting up and managing your projects with Git and GitHub. Let me know if you need further assistance!