Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 76 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save ZeroDragon/6707408 to your computer and use it in GitHub Desktop.
Save ZeroDragon/6707408 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

@LaBlatta
Copy link

LaBlatta commented Aug 8, 2021

Thanks! Also this:

git checkout origin/master -b master

Is exactly what I was looking for!

@kokhoor
Copy link

kokhoor commented Sep 25, 2021

Great simple steps. Thanks!

@hrishikeshps
Copy link

Many Thanks @sochi ..

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