How to convert existing non-empty directory into a Git working directory and push files to a remote repository
Given you've set up a git daemon on <url>
and an empty repository:
cd <localdir>
git init
git add .
git commit -m 'message'
git remote add origin <url>
git push -u origin master
This is how I do. I have added explanation to understand what the heck is going on.
Initialize Local Repository
first initialize Git with
git init
Add all Files for version control with
git add .
Create a commit with message of your choice
git commit -m 'AddingBaseCode'
Initialize Remote Repository
Create a project on GitHub and copy the URL of your project . as shown below:
Link Remote repo with Local repo
Now use copied URL to link your local repo with remote GitHub repo. When you clone a repository with git clone, it automatically creates a remote connection called origin pointing back to the cloned repository. The command remote is used to manage set of tracked repositories.
git remote add origin https://github.com/hiteshsahu/Hassium-Word.git
Synchronize
Now we need to merge local code with remote code. This step is critical otherwise we won't be able to push code on GitHub. You must call 'git pull' before pushing your code.
git pull origin master --allow-unrelated-histories
Commit your code
Finally push all changes on GitHub
git push -u origin master
Here's my solution:
git init
git remote add origin PATH/TO/REPO
git fetch
git checkout -t origin/master