DEV Community

Cover image for How to Create a New Project and Push to GitHub from your Local Machine
Ifechukwu Obiezue
Ifechukwu Obiezue

Posted on

How to Create a New Project and Push to GitHub from your Local Machine

This is something we already know how to do, but for reference sake am documenting this here.

To create a new project and push it to GitHub from your local machine, you'll need to follow these general steps:

  1. Install Git: If you haven't already, download and install Git on your local machine. You can get it from the official Git website: https://git-scm.com/

  2. Create a New Repository on GitHub:

    • Log in to your GitHub account.
    • Click on the "+" sign in the top right corner of the page.
    • Select "New repository."
    • Enter a name for your repository, add a description if you want, and choose any other settings you need (public or private, initialize with a README, etc.).
    • Click on the "Create repository" button.
  3. Set up Git on Your Local Machine:

    • Open a terminal or command prompt on your local machine.
    • Configure Git with your name and email address:
     git config --global user.name "Your Name"
     git config --global user.email "your_email@example.com"
    
  4. Navigate to Your Project Directory:

    • Use the cd command to navigate to the directory where you want to create your project.
  5. Initialize a Git Repository:

    • Run git init to initialize a new Git repository in your project directory.
  6. Add Your Files to the Repository:

    • Copy or create the files you want to include in your project into the repository directory.
    • Use git add . to add all files in the current directory to the staging area. You can also specify individual files instead of . to add only specific files.
  7. Commit Your Changes:

    • After adding files to the staging area, commit them to the repository with a commit message:
     git commit -m "Initial commit"
    
  8. Link Your Local Repository to GitHub:

    • On GitHub, copy the URL of your repository (should look like https://github.com/username/repository-name.git).
    • Back in your terminal, add the remote repository URL using:
     git remote add origin https://github.com/username/repository-name.git
    
  9. Push Your Changes to GitHub:

    • Finally, push your committed changes to the GitHub repository:
     git push -u origin master
    
  • If you are using a different branch name, replace master with your branch name.
  1. Authenticate with GitHub:
    • If prompted, enter your GitHub username and password or token to authenticate and push your changes.

After completing these steps, your project files should be successfully pushed to GitHub, and you can view them in your GitHub repository online.

⚡Feel free to reference back to this guide at any time.

Top comments (1)

Collapse
 
kachi14 profile image
Ukwueze Onyedikachi

Yeah this is a nice beginner's guide