Git Cheatsheet

What is git

Git is a versioning control system.

What to control

Anything really. I personally use it for this site, personal code projects, backing up things ...

Usage

To get started with a repo you must

  1. Setup your user account. This isn't going to a website necessarily to create and register. This is telling git some basics. Now, on fancier tools such as GitLab or GitHub, you can use your ssh public key for authenticating to your repos. But for less fancy things you will need to setup a email/password combination. Additional options are the editor used for the commit messages, and your diff tool. Some GUI tools can handle reading this in, and modifying them. I use only linux and the terminal for my tasks, so I can't speak for OSX/Windows GUI tools at all, and have only briefly used a few linux ones (GitCola, GitG).
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
git config --global core.editor emacs
git config --global merge.tool vimdiff
# Check your settings:
git config --list
  1. Clone the repo. This will be the first pull done, presuming you have nothing and need to be current with whatever branch you are going to be working with. Some projects are utilizing multiple branches, others just one.
cd /path/to/where/you/want/the/files/to/go/
git clone URL_OF_REPO
  1. As changes are made by those that have modification rights, you will obviously need to grab them. This is a pull.
cd /project/root/directory/
git pull
  1. If you were are someone who is authorized to make changes (commits), have made them, and would like to upload commits to the repo, this is called a push.
cd /project/root/directory/
git add .
git commit
git push -u REPO BRANCH
# Example to a GitLab repo:
# git push -u origin master

I mucked something up and can't re-pull

git fetch --all
git reset --hard origin/master

Additional reading

https://git-scm.com/book/en/v1/Getting-Started https://help.github.com/articles/set-up-git/