New to GitHub, still trying to figure out the mechanism and here're some notes re how to connect local folder with a repo and vice versa:
It is recommended to create a repository directly from GitHub.com by using the beautiful and minimal UI provided. So do that before anything else.
Now, there are two ways to connect a local folder to a repo on the site:
- clone --> copy & paste locally --> add --> commit
- 2.2 init --> add --> commit --> git remote origin --> pull --> push
# get the empty repository you just created to a local folder
# whose name is automatically set to be the same as your repo
$ git clone <URL>
# Here is when you copy and paste the stuff you want to upload to your repo
# adding/staging the files before commit
$ git add .
# just to check if everything has been added
$ git status
# commit
$ git commit -m 'comment goes here'
# push
$ git push origin master
# or simply git push
Note: can be HTTP url or SSH, using SSH you need to set up SSH Key first, just in case you don't know how.
You can also just use $ git commit -a -m 'comment'
without having to git add .
if you don't have completely new files in the folder.
This is slightly more difficult and sometimes doesn't work if you are not careful.
# create a local folder which ideally should be the same as the repo name you just created
$ mkdir <REPONAME>
# Change Directory into this folder
$ cd <REPONAME>
# make it a git monitored folder, assuming you've already got [git installed](https://git-scm.com/downloads)
$ git init
# adding/staging the files before commit
$ git add .
# just to check if everything has been added
$ git status
# commit
$ git commit -m 'comment goes here'
# set the remote destination to which the local folder is expected to connect
$ git remote origin <URL>
# pull request: make sure no conflict with the remote repo, basically all of the files on the repo have to be local first, it is recommended to git pull before git push. In fact, it'll prompt error if you have any files in the repo only and not local
$ git pull
# push
$ git push origin master
Note:
- can be HTTP url or SSH, using SSH you need to set up SSH Key first, just in case you don't know how.
- if you
git remote origin
set to a wrong url, you can usegit remote set-url <URL>
to reset it to the correct one