Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vihatsoft/23b97ab30115c68d15b117d278dae70f to your computer and use it in GitHub Desktop.
Save vihatsoft/23b97ab30115c68d15b117d278dae70f to your computer and use it in GitHub Desktop.
How to clone a git repo to an existing folder (not empty)
  1. First get to the existing directory
    $ cd my/folder/

  2. Now start a new git repository
    $ git init

  3. Identify if the current elements on the directory are needed or not and add them to the .gitignore file. When ready...
    $ vim .gitignore

  4. When ready create the first commit on the server
    $ git add .;git commit -m'my first commit'

  5. Now add the remote from where you want to clone
    $ git remote add origin https|ssh:path/to/the/repository.git

  6. Now just pull and merge with local git
    $ git pull origin master

  7. If you have some merge conflicts resolve them and commit your changes.

You are ready to go!

UPDATE

If your remote repository is NOT empty, you must do what Sochi pointed out here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment