Using 'git remote' to add a remote origin manually
Before reading this post please understand what 'local' and 'remote' repositories in git means. This is very important to understand difference between local and remote git repositories.
In simple words,
local git repository is a directory which exists in your computer.
remote git repository is the directory which exists in your github account ( or say bitbucket ).
Suppose say you have some day-to-day-use shell scripts in your computer ( say in $HOME/.scripts/ directory ) and you want to store them into a new repository ( this remote repository doesn't exist yet ) in your Github account.
Note: You are not cloning a remote git repository into your machine here at all. You are just pushing your already existing local scripts into a newly created remote git repository using 'git remote'.
Do the following things
Go to your github page and create a new repository called 'scripts'
Now go to your local directory which contains the scripts ( which is in your machine ) and initiate a new empty local git repository using this command git init
Now add the file contents to index using git add *
Commit the changes git commit -m "adding scripts"
Since this local_repository/scripts_directory is not a clone of any remote git repository yet, no remote origin exists for this local directory. You have to add the manually created 'scripts' directory as remote origin ( See first bullet ) git remote add origin https://github.com/<github-username>/scripts.git
Last step is to push the local scripts to remote repository git push -u origin master
Now go to https://github.com/<github-username>/scripts
Voila !!!










