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:
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/
-
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.
-
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"
-
Navigate to Your Project Directory:
- Use the
cd
command to navigate to the directory where you want to create your project.
- Use the
-
Initialize a Git Repository:
- Run
git init
to initialize a new Git repository in your project directory.
- Run
-
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.
-
Commit Your Changes:
- After adding files to the staging area, commit them to the repository with a commit message:
git commit -m "Initial commit"
-
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
- On GitHub, copy the URL of your repository (should look like
-
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.
-
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)