Satyam Arya

Pushing Local Repository to GitHub Using Git: A Step-by-Step Guide

If you have source code stored locally on your computer, you can add the code to GitHub by typing commands in a terminal. You can do this by typing Git commands directly, or by using GitHub CLI.

Git installation steps: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git

GitHub CLI is an open source tool for using GitHub from your computer’s command line. GitHub CLI can simplify the process of adding an existing project to GitHub using the command line.

Step 1:

Create a new repository on GitHub: If you haven’t already, create a new repository on your GitHub account

Step 2:

Open Git Bash in the root directory of your local project.

git bash

Then, run the following command to initialize a new Git repository:

git init

This will create a new Git repository in your project directory.

Step 3:

Add your files to the Git repository: Use the git add command to add your project files to the Git repository. For example:

git add .

This command stages all files in the current directory and its subdirectories.

Step 4:

Commit your changes: Use the git commit command to commit your changes. For example:

git commit -m "Initial commit"

This command commits all staged changes with the message “Initial commit”.

Step 5:

Add your GitHub repository as a remote: Run the following command to add your GitHub repository as a remote:

git remote add origin <repository-url>

Replace <repository-url> with the URL of your GitHub repository.

Step 6:

Push your changes to GitHub: Finally, use the git push command to push your changes to your GitHub repository. For example:

git push -u origin master

This command pushes your changes to the “master” branch of your GitHub repository.

That’s it! Your local repository should now be added to GitHub using Git.

Warning: Never git add, commit, or push sensitive information to a remote repository. Sensitive information can include, but is not limited to:

In conclusion, pushing code to GitHub is an important skill for developers who want to collaborate on projects, share code with others, or simply keep a backup of their work. Whether you’re using the GitHub web interface or the command line interface (CLI), the process is relatively straightforward. By following the steps outlined in this guide, you should be able to successfully push your code to GitHub and start collaborating with others. Remember to always commit and push your changes frequently to ensure that your work is backed up and easily accessible to others.

Check our other articles: https://satyam-arya.click/hosting-wordpress-on-amazon-ec2/

Exit mobile version