The Hitchhiker's Guide to Git
This is a beginner's guide to the Git version control system. This is mostly a note to myself, but I hope it's useful to others as well.
Getting Started
Before using Git, you need to set the user info. It will be displayed in the commit log.
git config --glocal user.name "your name" git config --glocal user.email "email"
Check the config file with git config --list or cat ~/.gitconfig
There are two ways to have a git repository.
- Creating a new repository:
git init - Copying from a remote repository:
git clone git@example.tld:/project.git
After editing files (created gpacalculator.py in the example), check the tracking status with git status
Example output:
# On branch master # # Initial commit # # Untracked files: # (use "git add..." to include in what will be committed) # # gpacalculator.py
Recording Changes
Start tracking gpacalculator.py with git add gpacalculator.py
git add .will add everything in the working directory and the subdirectories.
Now git status will show:
# Changes to be committed: # (use "git rm --cached..." to unstage) # # new file: gpacalculator.py
git commit -m "comment" will record the change to the repository. Comments are required.
Alternatively, git commit -a will commit with all changes added and git commit -v will show the differences. See man git-commit for more options.
Logging
Branching
Remote Repositories
This guide is currently being updated.
Tips
git config --global alias.co checkout
Check Git version with git --version
