Githandson: Difference between revisions
From Gridkaschool
Jump to navigationJump to search
Line 39: | Line 39: | ||
==Exercise 3 (Working with remote repository) == |
==Exercise 3 (Working with remote repository) == |
||
* Clone the remote repository and examine the log |
* '''Clone the remote repository and examine the log ''' |
||
** $ git clone gitolite3@gridkapuppet01:test2.git |
** $ git clone gitolite3@gridkapuppet01:test2.git |
||
** $ git log |
** $ git log |
||
*Look in .git directory at the config file |
*'''Look in .git directory at the config file''' |
||
**edit config file and delete [remote "origin"] section |
**edit config file and delete [remote "origin"] section |
||
** add remote repository by doing: |
** add remote repository by doing: |
||
Line 50: | Line 50: | ||
* Add a new file to local repository and submit the changes to remote: |
* '''Add a new file to local repository and submit the changes to remote: ''' |
||
** $ git add <new file> |
** $ git add <new file> |
||
** $ git diff HEAD |
** $ git diff HEAD |
||
** $ git commit -am "some comment" |
** $ git commit -am "some comment" |
||
** $ git push -u origin master ( -u - set-upstream ref) |
** $ git push -u origin master ( -u - set-upstream ref) |
||
* try: |
* '''try: ''' |
||
**$ git fetch |
**$ git fetch |
||
**$ git rebase |
**$ git rebase |
Revision as of 17:47, 24 August 2016
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!
Exercise 1 (Configuration)
- $ login to gridkalogin01
- $ mkdir project
- $ cd project
- 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
Exercise 2 (Basics)
Let's commit some stuff to git...
- $ git init
- $ git status
- $ touch readme.txt
- $ echo "hello" > readme.txt
- $ git commit
- $ git add .
- $ git commit
- $ git "bye" >> readme.txt
- $ git status
- $ git reset
Exercise 3 (Working with remote repository)
- Clone the remote repository and examine the log
- $ git clone gitolite3@gridkapuppet01:test2.git
- $ git log
- Look in .git directory at the config file
- edit config file and delete [remote "origin"] section
- add remote repository by doing:
- $ git remote add origin gitolite3@gridkapuppet01:test2.git
- Add a new file to local repository and submit the changes to remote:
- $ git add <new file>
- $ git diff HEAD
- $ git commit -am "some comment"
- $ git push -u origin master ( -u - set-upstream ref)
- try:
- $ git fetch
- $ git rebase
- 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 cheat sheet
Git configuration
- Git levels:
/etc/gitconfig - global git config for any user
~/.gitconfig -user specific
~/repo/.git/config -repo specific
each level ovewrites prevous.
git config --global user.name "Your Name"
git config --global user.email you.email@domain
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
Git basics
git init - create new local repo git clone /path/to/repository - check out a repository git clone https://github.com/ - clone repo from github git add <filename> - add specified file to staging area git add . - add all subdirectories and files recursivly git commit - commit the staged files git commit -am "some comment" - stage changes and commit in one step git rm <filename> - remove deleted file git reset - removes all added files from staging area, keeps the changes git reset --hard - removes all added files from staging area, drops the local changes after last commit git checkout -- . - discards all local changes which are not staged git status - List the files you've changed and those you still need to add git help - Help for most commonly used git commands git help <command> - Detailed help for specified command git init --bare --shared - Creates empty repository meaning no working directory in it. git remote add origin REMOTEURL - git remote add creates an entry in your git config that specifies a name of a particular URL of the remote git remote rm origin - removes added remote repository git repo. This command can be used only after creation of local repo with git init or git clone. git remote -v - This should show you all of the push/fetch remotes for the project. git clone - creates a new git repository by copying an existing one located at the URI you specify.