To see git in action, let’s create a new repository, add some content, and manage a few revisions.
There are two fundamental techniques for establishing a Git repository. You can either create it from scratch, populating it with an existing body of work, or you can copy, or clone, an existing repository. It’s simpler to start with an empty repository, so let’s start there.
To model a typical situation, let’s create a repository for your personal website from the directory ~/public_html and place it in a Git repository.
If you don’t have content for your personal website in ~/public_html, create the directory and place some simple content in a file called index.html:
echo 'My website is alive!' > index.html
To turn ~/public_html or any directory into a Git repository, run git init:
git initInitialized empty Git repository in .git/
Git doesn’t care whether you start with a completely empty directory or with a directory full of files. In either case, the process of converting the directory into a Git repository is the same.
To signify that your directory is a Git repository, the git init command creates a hidden directory, called .git, at the top level of your project. Whereas CVS and Subversion place revision information in CVS and .svn subdirectories within each of your project’s directories, Git places all its revision information in this one top-level .git directory. The contents ...