Open In App

GitPush With (Visual Studio) VS Code

Last Updated : 26 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Visual Studio Code (VS Code) is a powerful and versatile code editor widely used by developers. One of its standout features is its seamless integration with Git, making version control very simple. In this article, we'll explore how to GitPush With (Visual Studio) VS Code.

Steps To Create And Add Git Repository in VS Code

Step 1: Open the VS code, then open a new terminal and create a new empty folder using this command

mkdir gfg

Go to this folder using the following command.

cd gfg
terminal
open terminal

Step 2: Then open our folder new terminal and create new react project using this command

npx create-react-app gfgreact
create
create react project

Step 3: Then initialize with git repository using this command

 git init 
init
git init

Step 4: Go to the react project and open src folder and open App.js file and add some code then

run this project using this command: npm start

import './App.css';

function App() {
return (
<div className="App">
<header className="App-header">
<h2>Hello GFG</h2>
</header>
</div>
);
}

export default App;
run
run

Step 5: Return the vs code terminal and check the status of git repository using this command

git status 
status
git Status

Step 6: Then add all changes in git using this command:

git add

Check the status using this command

git status
add
git add .
check
git status

Step 7: Then commit all changes using this command : git commit -m "change the app.js file" and check the status using this command

git status
commit
commit all changes

Step 8: These are the changes made in the local system but we want to upload the project which we created in your system to GitHub then follow the below steps to upload :

  1. Go to the GitHub
  2. then click your profile
  3. select your repositories folder
GitHub
Go to GitHub
profile
profile
repository
select option
goto-repo
go to repository

Step 9: Then click on new button and create new repository and give the name like GFGRepo and check that our repository is created successfully or not then copy the repository link.

new
new button
repo
repo name
click
click this button
check2
successfully
copy
copy this link

Step 10: Then go to vs code terminal and get the remote of our git repository using this command

git remote add origin https://github.com/HerryVaghasiya/GFGRepo.git
remote
get remote

Step 11: check that repository remote is success fully added or not using this command

git remote -v

Check our git repository branch using this command

git branch

Change the branch name master to main because GitHub change its default branch name master to main so rename our branch name using this command:

git branch -M main

Check branch name

git branch 
remotev
check remote
branch
check branch
change
change and check branch name

Step 12: Then push our code in GitHub repository using this command

git push -u origin main

(Note : -u means set upstream. If you want to work on the same project for a long time, there is a shortcut key that will set the branch name as default so that you don't have to give the same branch name every time. )

push
push the code

Step 13: Then Go to GitHub repository and refresh the page and check that our project is successfully pushed or not.

pushed
project successfully pushed

Next Article
Article Tags :

Similar Reads