Browse to the git website and download the tar ball
wget https://www.kernel.org/pub/software/scm/git/git-2.10.2.tar.gz
tar -xvf git-2.10.2.tar.gz
rm -r git-2.10.2.tar.gz
cd git-2.10.2
Look at the install file using less INSTALL
make configure
./configure --prefix=$HOME/software/git
make -j16 all doc
make install install-doc install-html
export PATH=$HOME/software/git/bin:$PATH
which git
git --version
git init starterkit-2016
- This makes a directory called
.git
git status
Make a file containing the above instructions
git status
git add git_cheatsheet.txt
git status
git commit -m "Add instruction to initialise a repository"
We got an error about not having our name and email set, look at the log:
git log
We'll have to set it then fix it using the printed suggestion:
git config --global --edit
git commit --amend --reset-author # Warning: Here be vim based dragons
git log
This just created a file called ~/.gitconfig
, as this config was set globally
Let's update the instructions with how to commit a file
git add -u
git status
git diff
git add -u
git status
git diff
Where did our change go? It's staged!
git diff --staged
git commit -m "Adding staging instructions" # Hey see we don't get a warning this time
git log
Oops I'm an idiot (edit the file and accidentally delete everything)
git status
git diff
git reset --hard HEAD
Let's make another file, then add/remove it from the staging area.
git add quick_notes.txt
git reset
git diff HEAD~1
Let's commit some changes and include the quick_notes.txt
file by accident
git add . # Explain
# Don't use status so we can accidentally commit the file
git commit -m "Helpful viewing commands"
Oops!
git reset HEAD~1
It's important to remember we haven't actually backed anything up yet. If you delete this entire folder, or use a bad combination of git commands you could delete everything!
Now let's all make a github account...
git remote --verbose
git remote add origin git@github.com:chrisburr/starterkit-2016-example.git
git remote --verbose
git push -u origin master
Go look at your creation online
Make another change, commit, git push
and it appears online
If you edit your commit and try to push you get an error
git push --force origin master
git checkout -b python-notes
# Make a trivial python script and commit
git push -u origin python-notes
git checkout master # Why don't I have '-b'?
# make the README
# push and check it
git checkout -b bash-notes
# Make a file
git push -u origin bash-notes
Go back and add a python module, run it, commit and push
Hey, what's this .pyc
file?
git rm
git commit
git push
Add python to the README
It's annoying that we keep committing this pyc file, introducing .gitignore
git checkout master
git merge python-notes
git push # Then checkout the graph
Actually I'm happy with bash notes, lets also merge that
git merge bash-notes
# Why are we ahead by two commits on git status?
git push
We can make git log prettier using arguments, I can't remember them so lets go Google "git log show graph".
git log --graph --abbrev-commit --decorate --all # plus formatting