- by Rutu Shah
Today, we came up with the concept of git, in this blog I will guide you for adding an existing project into your GitHub repository using the command line.
Note: These steps will work for git cmd, IntelliJ terminal, and Vscode to where you want to add project through command line/terminal.
Step 1: So let’s begin, by creating one new repository on Github. You can also add readme, license or git ignore files too at the time of creating the repository.
Create new repository
Step 2: Open the IntelliJ project which you want to add on Github.
Step 3: Open Terminal.
Step 4: Initialize the Local directory with Git Repository as shown in the given figure and also I am adding the command too.
git init
Step 5: Now add all the files to your new local repository, which stages them for the first commit.
git add .
Adds all the files present in the local repository which stages themt o commit, If you want to unstage a file, use 'git reset HEAD YOUR-FILE'.
Step 6: Now, commit the files which you have staged.
git commit -m "Initial Commit"
This command commits the tracked changes and prepares them to be pushed to a remote repository. Incase,if you want to remove this commit and modify the file, you can use 'git reset --soft HEAD~1' and then after perform commit and add the file again.
Step 7: At the top of your GitHub repository on the right-hand side hover on the code button and copy the remote repository URL.
Copy remote url.
Step 8: Add the URL for the remote repository, in the terminal from where your local repository will be pushed.
git remote add origin <YOUR_REMOTE_URL>
This command sets the new remote url for you.
Step 9: To verify the added remote URL you can verify with the following command.
git remote -v
This command verifies the new remote URL.
Step10: Now to push the changes from the local repository to GitHub, we have the following command.
git push origin main
This command pushes the changes in your local repository upto the remote repository you specified as the origin.