Pushing code from VS Code to GitHub involves a few steps
Ensure Git is installed on your system.
Download Git and install it.
To verify, run this command in your terminal:
2. Configure Git (First-Time Setup)
Set your name and email in Git:
git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"
3. Create a GitHub Repository
Go to GitHub and log in.
Click the + icon in the top-right corner and select New repository.
Name your repository and optionally initialize it with a README file.
4. Open Your Project in VS Code
Open your project folder in VS Code.
If your project isn’t already a Git repository, initialize it:
Open the VS Code terminal and run:
5. Link Your Project to the GitHub Repository
Copy the repository URL from GitHub:
Go to your GitHub repository.
Click the Code button and copy the HTTPS or SSH URL.
In the VS Code terminal, link the repository:
git remote add origin <repository-URL>
6. Add and Commit Your Changes
Commit your changes with a message:
git commit -m "Initial commit"
Push your code to the main branch (or the branch you’re using):
git branch -M main
git push -u origin main
Go to your GitHub repository, and you should see your code!
1. Pull Changes from the Remote Repository
Run the following command in your terminal to fetch and merge the changes from the remote repository into your local branch:
git pull origin main --rebase
What This Does:
git pull: Fetches the changes from the remote repository.
origin main: Specifies the remote (origin) and branch (main).
--rebase: Applies your local changes on top of the remote changes to avoid conflicts.
2. Resolve Any Merge Conflicts (If Applicable)
If there are conflicts, Git will notify you.
Open the conflicted files in VS Code, resolve the conflicts, and then stage the changes:
After resolving all conflicts, continue the rebase process:
3. Push Your Changes to GitHub
Once the pull is successful and conflicts (if any) are resolved, push your changes: