Steve Steve - 2 months ago 8
Git Question

Working with git in local machine to upload

I am very new with

git
version control.
I have the project in a directory. I have done these steps:


  • Navigated to the project directory.

  • git init

  • git add .

  • git commit -m "First commit"



And tried to upload to guthub using

git add remote origin https://github.com/userName/repo.git


but it gives


fatal: pathspec 'remote' did not match any files

Answer

Your syntax to add remote is wrong. The correct syntax is git remote add origin {remote_upstream_name} according to which you have to use

git remote add origin https://github.com/userName/repo.git.

After you execute this command, you will have origin as remote. You can verify this by executing git remote -v which should display your origin name along with url as:

# Verify new remote
origin  https://github.com/user/repo.git (fetch)
origin  https://github.com/user/repo.git (push)

Then you can push your changes to the remote origin using following command.

git push -u origin master

Here -u will keep your current branch in sync with your remote branch so from next time you can just do git push and it will push your changes to the remote branch. It also depends on other configs so you have to know about git push see git-push.

Hope this clears your confusions. Let us know if this helps you or not.

Comments