Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sochi/0ab9e5d1dd53410c82e7f1ae6abcfc6c to your computer and use it in GitHub Desktop.
Save sochi/0ab9e5d1dd53410c82e7f1ae6abcfc6c to your computer and use it in GitHub Desktop.
Clone a git repository to an existing non-empty folder

Clone a git repository to an existing folder

  1. Get to the existing directory
cd my/folder/
  1. Now start a new git repository
$ git init
  1. Identify if the current elements on the directory are needed or not and add them to the .gitignore file
vi .gitignore
  1. Configure username and e-mail address (unless already set globally from before)
git config user.name "Mona Lisa"
git config user.email "mona.lisa@participate.in.project.tld"
  1. Optionally set username and e-mail globally for all your repositories
git config --global user.name "Mona Lisa"
git config --global user.email "mona.lisa@in.louvre.fr"
  1. When ready create the first commit
git add .
git commit -m 'Initial commit'
  1. Set the remote from where you want to clone
git remote add origin https|ssh:path/to/the/repository.git
  1. Now just pull and merge with local repository
git pull origin master --allow-unrelated-histories
  1. If you have some merge conflicts resolve them and commit your changes

  2. Push your changes

git push -u origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment