Skip to content

Instantly share code, notes, and snippets.

@desaiuditd
Forked from davisford/gist:5039064
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save desaiuditd/c66c7c4a56f43abf5d5d to your computer and use it in GitHub Desktop.
Save desaiuditd/c66c7c4a56f43abf5d5d to your computer and use it in GitHub Desktop.
git clone in non-empty directory

Let's say you start a project locally, and do some editing.

$ mkdir -p ~/git/foo && cd ~/git/foo
$ touch NEWFILE

Now you decide you want to create a new github repo and track it, but the directory is non-empty so git won't let you clone into it. You can fix this, thusly:

$ cd ~/git/foo
$ git init
$ git remote add origin git@github.com:yourname/foo.git
$ git fetch
$ git branch master origin/master
$ git checkout master
$ git add -A
$ git commit -m 'first commit'
$ git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment