Difference between revisions of "Githandson"

From Gridkaschool
(Git Hands-on)
(Git Hands-on)
Line 2: Line 2:
   
 
'''All of these exercises should be followed on naf-school03 using your school account'''
 
'''All of these exercises should be followed on naf-school03 using your school account'''
  +
'''''Note that lines beginning with a $ sign implies a shell command!'''''
   
* mkdir -p ~/school/git
+
* $ mkdir -p ~/school/git
* cd ~/school/git
+
* $ cd ~/school/git
* Configure git
+
* '''Configure git'''
** git config --global user.name "Your Name"
+
** $ git config --global user.name "Your Name"
** git config --global user.email you.email@domain
+
** $ git config --global user.email you.email@domain
   
* cat ~/.gitconfig
+
* $ cat ~/.gitconfig
   
* optional extras for config (and obviously editor is mutually exclusive)
+
* '''optional extras for config (and obviously editor is mutually exclusive)'''
** git config --global color.ui auto # If you like colours!
+
** $ git config --global color.ui auto # If you like colours!
** git config --global alias.co checkout
+
** $ git config --global alias.co checkout
** git config --global alias.st status
+
** $ git config --global alias.st status
** git config --global alias.ci commit
+
** $ git config --global alias.ci commit
** git config --global core.editor emacs # flame bait
+
** $ git config --global core.editor emacs # flame bait
** git config --global core.editor vim
+
** $ git config --global core.editor vim
   
* git clone git@naf-school04:gitlab
+
* $ git clone git@naf-school04:gitlab
* cd puppet
+
* $ cd puppet
* git status
+
* $ git status
* vi ${USER}.txt
+
* $ vi ${USER}.txt
** write something
+
** ''write something''
* git status # what is updated? Working tree, Index or Repository?
+
* $ git status # ''what is updated? Working tree, Index or Repository?''
** git diff
+
** $ git diff
** git diff HEAD
+
** $ git diff HEAD
** git diff --cached
+
** $ git diff --cached
* git add ${USER}.txt
+
* $ git add ${USER}.txt
** git status
+
** $ git status
** git diff
+
** $ git diff
** git diff HEAD
+
** $ git diff HEAD
** git diff --cached
+
** $ git diff --cached
* git commit -m "Add user text file"
+
* $ git commit -m "Add user text file"
** git status
+
** $ git status
** git diff
+
** $ git diff
** git diff HEAD
+
** $ git diff HEAD
** git diff --cached
+
** $ git diff --cached
* git push origin master
+
* $ git push origin master
** this might not work! Why?
+
** ''this might not work! Why?''
** tip: what does “git pull --rebase” do?
+
** ''tip: what does “git pull --rebase” do?''
* git checkout -b ${USER} master # specifying "master" here is just a good habit. Always beware of defaults.
+
* $ git checkout -b ${USER} master # specifying "master" here is just a good habit. Always beware of defaults.
* vi config.yaml
+
* $ vi config.yaml
** Add a user to the list
+
** ''Add a user to the list''
* git add -p
+
* $ git add -p
* git commit -m "Adding ${USER} to users list"
+
* $ git commit -m "Adding ${USER} to users list"
* git push origin ${USER}
+
* $ git push origin ${USER}
* git checkout master
+
* $ git checkout master
* git merge ${USER}
+
* $ git merge ${USER}
* git push origin master
+
* $ git push origin master
** What happens?
+
** ''What happens?''
* git checkout -b newfeature_${USER} master
+
* $ git checkout -b newfeature_${USER} master
* vi config.yaml
+
* $ vi config.yaml
** add a server
+
** ''add a server''
** commit the change (with a good message!)
+
** ''commit the change (with a good message!)''
** git log
+
** $ git log
* Oops! We mistyped the server, vi config.yaml again
+
* ''Oops! We mistyped the server, vi config.yaml again''
** change the name of the server
+
** ''change the name of the server''
** commit the change
+
** ''commit the change''
** git rebase -i HEAD~2
+
** $ git rebase -i HEAD~2
** use “fixup” or “squash” on the fix (make sure you understand the difference)
+
** ''use “fixup” or “squash” on the fix (make sure you understand the difference)''
** git log # examine the differences
+
** $ git log # examine the differences

Revision as of 10:08, 8 September 2015

Git Hands-on

All of these exercises should be followed on naf-school03 using your school account Note that lines beginning with a $ sign implies a shell command!

  • $ mkdir -p ~/school/git
  • $ cd ~/school/git
  • Configure git
    • $ git config --global user.name "Your Name"
    • $ git config --global user.email you.email@domain
  • $ cat ~/.gitconfig
  • optional extras for config (and obviously editor is mutually exclusive)
    • $ git config --global color.ui auto # If you like colours!
    • $ git config --global alias.co checkout
    • $ git config --global alias.st status
    • $ git config --global alias.ci commit
    • $ git config --global core.editor emacs # flame bait
    • $ git config --global core.editor vim
  • $ git clone git@naf-school04:gitlab
  • $ cd puppet
  • $ git status
  • $ vi ${USER}.txt
    • write something
  • $ git status # what is updated? Working tree, Index or Repository?
    • $ git diff
    • $ git diff HEAD
    • $ git diff --cached
  • $ git add ${USER}.txt
    • $ git status
    • $ git diff
    • $ git diff HEAD
    • $ git diff --cached
  • $ git commit -m "Add user text file"
    • $ git status
    • $ git diff
    • $ git diff HEAD
    • $ git diff --cached
  • $ git push origin master
    • this might not work! Why?
    • tip: what does “git pull --rebase” do?
  • $ git checkout -b ${USER} master # specifying "master" here is just a good habit. Always beware of defaults.
  • $ vi config.yaml
    • Add a user to the list
  • $ git add -p
  • $ git commit -m "Adding ${USER} to users list"
  • $ git push origin ${USER}
  • $ git checkout master
  • $ git merge ${USER}
  • $ git push origin master
    • What happens?
  • $ git checkout -b newfeature_${USER} master
  • $ vi config.yaml
    • add a server
    • commit the change (with a good message!)
    • $ git log
  • Oops! We mistyped the server, vi config.yaml again
    • change the name of the server
    • commit the change
    • $ git rebase -i HEAD~2
    • use “fixup” or “squash” on the fix (make sure you understand the difference)
    • $ git log # examine the differences