Start a new Github repo from an existing project

Suppose you have a project and wish to start tracking it with Github, Bitbucket or AWS CodeCommit.

First you need to navigate to the project folder locally & run the following command to initialize the git.

git init .

One of the best practices when using git is to maintain project .gitignore file, in order to ignore files & folders when pushing files to the remote repo.

Then add all files & folders from current project and do commit by running the following command.

git add .
git commit -m"A message for the commit"

Assuming that you have already repo in for example Github, let connect the local repo to the remote Github repo by running the folowing commands.

git remote add origin
git pull origin master --allow-unrelated-histories

Now it’s time to push project source to the remote repo by running the following command.

git push origin master
Flow Example
Flow Example

That is all you need to do, quite simple isn’t it 🙂

Author: Danyal
I'm working as programmer since 2002. Born, grew up, studied and worked in Pakistan now Im located in Denmark since 2006.