Getting started
git config --global user.name "Your Name" git config --global user.email "your_email@whatever.com"
Create a repository
mkdir test cd test git init
Create a files
Use your favourite text editor to create a file in the test directory.
We will assume it is called file1.txt
Add the file so that git knows it exists
git add file1.txt
Commit the changes to git
git commit -a -m "Some message about the file"
When you commit the file you must include a comment
If you don't do this on the command line you will be taken to an editor - by default this will be vi (a rather non-intuitive editor). You can override this with the command:
git config --global core.editor myeditor
See what has been logged by git
git log git status
Edit the file
Use your editor to make some changes to the file
See the differences between the new file and the old file:
git diff file1.txt
See what has been logged by git
git log git status
Commit the changes
git commit -a -m "Some message about the changes"
See what has been logged by git
git log git status
Undoing a commit
git revert HEAD
Get an older version
Get the hash of an older version
git log git checkout HASH-NUMBER cat file1.txt
Get back to the latest version
git checkout master
Create a branch
List existing branches
git branch
Create a new branch
git checkout -b newbranch
Merge the changes into the main branch
git checkout master git merge newbranch
Tagging
git tag v1
Removing a tag
git tag -d v1