Saturday, February 01, 2020

Pushing Your Stuff to Github

You have files on your computer you want to send to GitHub. 

If you said you have files in your directory you want to send to GitHub, I'd say... not so fast. If you don't know what you're doing, you might lose *all* of them!

What *should* you do?

Start with an empty directory.
Then

git init
git remote add origin https://github.com/username/repoName (yes, I assume you created it on GH :)
git pull origin master  // this is the magic that now tells your local system that you're hooked up
cp /from/path/file1 .    // may be overcautious..
git add file1
git commit -m "initial"
git push origin master

If you try the git remote add origin thing without the git init..

fatal: not a git repository (or any parent up to mount point /cygdrive)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

If you do the git init and the git remote add origin and then try pushing..

To https://github....
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/...
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

No comments: