Back

Git: Your First Repo

Git is version control software. Git is not GitHub. We should cover GitHub, but we'll do that in another article. For now, let's talk about the version control software. Git offers a number of helpful ways to control what your application's code looks like at any given moment. Let's look at commands available in the command line interface. Each of the following options have much more detail than will be addressed in this overview.

Creating a Repository

A repository, often called a repo by developers, is just a place for your code. Repos usually include a README.txt file that store information about the repo along with all the code. I should point out: a repo does not have to be code. That creates some interesting possibilities for using Git for all kinds of versioning of files, but usually, it's code and supporting files.

git init 'repo name'

This command establishes a repo named as you specify creating a directory by that name in the current directory. If you then go into that directory, cd 'directory name', you will be able to add your README.txt file.

Committing the README.txt

Committing your changes, the new README.txt, creates a point in the life of your repo that you can rollback to if the need arises. At this point, you can't simply type git commit because your new README.txt file is not being tracked unless you're using an IDE that automatically handles git repos. So your first step is to add the file to the index with git add 'filename', in this case,

git add README.txt

Once this is done, get the status of your repo with

git status.

What you see now, is your working tree. It shows you the branch you're working on and the files staged for your commit. Now, you're ready to commit your README.txt file to the master branch of your repo. If you just type

git commit

then your command line should turn into a text editor. This is so that you can create a commit message. Commit messages can be particularly helpful in identifying when specific changes were made to your code, but that will depend on the information you provide. Usually, a short descriptive first line, followed by an empty line, and then a longer description of the changes being committed are good practices. Then you'll have to press the ESC key and then :wq. Don't forget the colon. When you press enter, your changes will be committed, and the README.txt will now be part of your repo.

This is only the very beginning of what you can do with git, but this is a good start. Some other deeper subjects for git are branching and merging strategies, but that will be covered in a different article.

Some Helpful Git Commands

Need help?
git --help

Helpful links

Git Website
GitHub Website