How to Push Code to GitHub Using Git Bash

Mastercraft

Administrator
Staff member
Sep 17, 2024
21
10
3
What'supp guys, if you have been finding it hard to push your project or simple task of written code online, As you know pushing code to GitHub is essential for sharing your work with others or storing it in the cloud. Here's a beginner-friendly guide to help you push your code using Git Bash. Without ado, let dive in...

Step 1: Install Git

If you haven't installed Git and want to get it to install on your laptop or desktop, download and install it from Git's official website.

Step 2: Set Up Git with Your GitHub Account

If you don't have an account on GitHub, create an account. To learn how to create an account on GitHub, Click Here.
1. Open Git Bash and configure your user details​
Git:
git config --global user.name "Your GitHub Username"
git config --global user.email "your-email@example.com"
Step 3: Create a Local Git Repository
1. Navigate to your project folder in Git Bash
Git:
cd path/to/your/project
2. Initialize the local repository
Git:
git init
Step 4: Add Files to Your Repository

1. Add all files to the staging area
Git:
git add .
Or you can add specific files
Git:
git add filename.extension
Step 5: Commit Your Changes

Commit your files with a descriptive message
Git:
git commit -m "Initial commit"  # or your message

Step 6: Link Your Repository to GitHub
1. Create a new repository on GitHub (without initializing it).​

2. In Git Bash, add the GitHub repository as the remote origin​
Git:
git remote add origin https://github.com/your-username/repository-name.git

Step 7: Push Your Code to GitHub
1. Push the code to the master/main branch of your GitHub repository​
Git:
git push -u origin main  # or 'master' depending on your branch

Step 8: Verify Your Code on GitHub
Congratulation, you have successfully push your project online.
Go to your GitHub repository, and you'll see your project files successfully pushed.

If you preferred Video Tutorial, Watch Below by Sonnytech
To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.