So let's jump right into learning git.
Installation
Make sure you have git installed:$ git --version
git version 1.7.9.5
$ sudo apt-get install git-core
Setup
Change your git config:$ git config --global user.name "Firstname Lastname" $ git config --global user.email "your_email@youremail.com" $ git config --global color.ui trueThese were just shorcuts to editing ~/.gitconfig. See this by running:
$ cat ~/.gitconfigMake sure that git is ignoring files that don't need to be tracked. Edit ~/.gitignore
$ gedit ~/.gitignoreAnd put in:
*.pycThis will make git ignore all files that have the file extension .pyc, which are files that speed up the loading of python (google for more info).
Learn Git!
Now start the git immersion tutorial on lab 3 by going here. This will hopefully teach you git. I've got a few ammendments that you should follow:After Lab 5: Try out:
$ git diffThis will show you what has been added and removed in each file. Out of everything in git, I use this command the most.
Lab 8: This tells you how to interactively edit your commit messages. Don't worry about this. Just do:
$ git commit -m "Using ARGV" $ git statusLab 10: Just go over the first and second steps, that is:
$ git log $ git log --pretty=onelineThe other parts are unnecessary
Lab 11: There are lots of shortcuts here. The only thing you need to do is the hist alias:
$ gedit ~/.gitconfigAdd this to the bottom to the bottom and save:
[alias] hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=shortLab 13: Optional
Stop after lab 15
Revised lab 16 and 17:
Make sure you are on master and have no changes
$ git checkout master $ git statusThere should be no changes in either Now edit hello.rb:
# oops, this was a bad comment name = ARGV.first || "World" puts "Hello, #{ARGV.first}!"Check the difference:
$ git diffNow commit:
$ git add hello.rb $ git commit -m "Adding a bad commit" $ git statusThe status should be clean.
Look at the log:
$ git histTo go back to another commit, do use git reset:
$ git reset <hash>Where hash is the hash of the previous commit, as seen next to the commit in the hist or log. A hash is just random letters and numbers, like 72ba5ec.
Another way to do this is:
$ git reset HEAD~1This means "reset to the parent of HEAD, that is one commit before HEAD" Notice that you are now at the point right before adding and committing:
$ git status $ git diff $ git histGo ahead and undo the changes
$ git checkout hello.rbYour index and working directory should now have no changes:
$ git statusCongratulations! You should now know the basics of git. Remember, next time you want to initialize a repository, just do:
$ git init $ git add . $ git commit -m "Initializing directory"Later on: pushing/pulling/remote repositories merging branching github
No comments:
Post a Comment