[go: up one dir, main page]

0% found this document useful (0 votes)
12 views4 pages

Push Code To GitHub

This document provides a step-by-step guide on how to push a local project to GitHub for the first time using Git commands. It covers initializing Git, adding files, committing changes, creating a repository on GitHub, connecting the local project to GitHub, and pushing the code. Additionally, it addresses potential errors and includes a real-life example for clarity.

Uploaded by

Souvik Gon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Push Code To GitHub

This document provides a step-by-step guide on how to push a local project to GitHub for the first time using Git commands. It covers initializing Git, adding files, committing changes, creating a repository on GitHub, connecting the local project to GitHub, and pushing the code. Additionally, it addresses potential errors and includes a real-life example for clarity.

Uploaded by

Souvik Gon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Push code to GitHub

write git commands to push a on github step wise

Here are the step-by-step Git commands to push a local project to GitHub for the
first time:

✅ Step 1: Initialize Git in your project folder


bash

git init

💡 This command creates a hidden .git folder and starts tracking your project
with Git.

✅ Step 2: Add all files to Git staging area


bash

git add .

. means all files. You can also use git add filename for specific files.

✅ Step 3: Commit the changes with a message


bash

git commit -m "Initial commit"

✍️ A good commit message helps you remember what was done in that commit.

1/4
✅ Step 4: Create a new repository on GitHub
1. Go to https://github.com

2. Click New > Name your repo (e.g., my-project )

3. Don't initialize with README (to avoid conflicts)

4. Click Create repository

✅ Step 5: Connect your local project with GitHub


bash

git remote add origin https://github.com/your-username/your-repo-name.git

🔗 Replace with your actual GitHub repo URL.


You can verify the connection using:

bash

git remote -v

✅ Step 6: Push the code to GitHub


bash

git push -u origin main

📌 If your branch is called master instead of main , use:

bash

git push -u origin master

-u sets the upstream so next time you can just use git push .

2/4
🔄 Optional: If your code gives this error
error: src refspec main does not match any

That means your branch is not main . Run this to check:

bash

git branch

If it shows master , then:

bash

git push -u origin master

✅ Now your code is live on GitHub!

🧠 Real-Life Example:
Imagine you're building a portfolio website in a folder called portfolio .

bash

cd portfolio
git init
git add .
git commit -m "Initial portfolio setup"
git remote add origin https://github.com/souvik/portfolio.git
git push -u origin main

If you want, I can also guide you on how to make it private, add .gitignore , or
handle GitHub token authentication. Let me know!

3/4
4/4

You might also like