Set up a new Git repository with a new Git remote origin
The situation: You have local folder that you want to turn in to a new Git repository. You then want to hook up that repository to a new remote master repository.
On the remote machine
Create an empty remote repository.
mkdir /repos/project-directory/ cd /repos/project-directory/ git init --bare
On the local machine
Create the local repository and do the initial commit, then hook up the remote master.
cd /project-directory/ git init git add * git commit -m "Initial commit" git remote add origin ssh://example.com/repos/project-directory/ git push -u origin master
When I’m the only person working on a particular repo, I like to add this Git hook to auto-push to the remote origin whenever I do a local commit.
echo "git push -f" > /project-directory/.git/hooks/post-commit chmod +x /project-directory/.git/hooks/post-commit
And you’re done!