GIT - 4.5 Start with an existing project
This lesson shows how to add source control to an existing project that does not yet have a Git repository. The starting point is a terminal in our home directory with a projects folder where all our Git projects live. In the previous lesson we created a repository inside a test subfolder and then deleted it, so the folder is back to a plain directory without version control. We jump into it:
cd test
Inside, we have a coucou.html file. To confirm there is no repository yet, we list every file including hidden ones with ls -al: there is no .git directory anywhere.
Initializing the repository with git init
To put this folder under version control with Git, we use the git init command. The trailing dot is optional and refers to the current folder:
git init .
Git replies that it initialized an empty repository in the current folder. The shell prompt now shows the branch name master in front of the cursor, which is Git's way of telling us we are in a repository. A new ls -al confirms that a hidden .git directory has appeared next to coucou.html.
Running git status shows that coucou.html is currently untracked. That makes sense: even though the file existed before, the repository we just created is brand new and has never seen it. Since we destroyed the previous repository in the prior lesson, this is a fresh repository with no knowledge of the old commits or of the old coucou.html history. To bring the file under version control, we would now run git add coucou.html followed by git commit. This is the standard way to bootstrap version control on any existing project, whether it has one file or hundreds.