Push existing code to remote git repository

For the situation you have created a remote (master) repository on GitHub, BitBucket or OpenHub.

cd existing-project
git init
git add --all
git commit -m "Initial Commit"
git remote add origin https://github.com/user/project.git
git push origin master

Steps explained:

  • Change to source directory
  • Initialize git repository
  • Add and commit the changes (ignore unwanted files with .gitignore)
  • Add remote repository, replace user and project with your data
  • Push to repository with branch master, you may have to authenticate yourself at the server or ssh-key