perjantai 19. huhtikuuta 2013

Git homework

Home assignment was to learn GIT.
a) create one person local git storage
b) do multiple commits, some very random, and then return to the last working set of files (git reset)
c) try some git user interface for example giggle
d) put your git on server
e) clone git files for multiple computers and try that files are synchronizing between the computers

I am using Oracle VM Virtualbox with Xubuntu 12.10 64bit

Update repositories first
$ sudo apt-get update
Install git
$ sudo apt-get install git
Create new project folder somewhere, for example
$ mkdir project
$ cd project
Make this project to git project with
$ git init
(This creates a new subdirectory named .git that contains all of your necessary repository files — a Git repository skeleton. At this point, nothing in your project is tracked yet.)

Then create your code, text or what ever document.
$ nano code.py
Make the file ready for git
$ git add . (dot includes all files in that folder)
Commit it to git
$ git commit
Add some commit message and that's it.



try
$ git log
to see log of committed files.



The main tool you use to determine which files are in which state is the git status command. If you run this command directly after a clone, you should see something like this:

$ git status
# On branch master
nothing to commit (working directory clean)

Resetting git 

One of the common undos takes place when you commit too early and possibly forget to add some files, or you mess up your commit message. If you want to try that commit again, you can run commit with the

$ git commit --amend

git reflog is useful command to see where the project head is. You can think head as a metro train and the head means the first train. All other trains are previous commits in order.

$ git reflog

-h command shows good information, for example

$ git reset -h


And if you want to go back (reset the head) use
$ git reset --hard (commit number here)
$ git reset --hard 5bca300

BUT, if you want to push this now on the server you cant. You have to force it with
$ git push --force

Git GUI

$ sudo apt-get install giggle

Giggle is graphical user interface for Git. In the screenshot you can see that my project folder has some random files and giggle shows graphical line for all the commits I have done. There is a short log, authors name and date of course.


From offline to online --> tutorial http://terokarvinen.com/2012/git-from-offline-to-network

I created a git repository on my raspberryPi.

$ ssh myname@ipofmyserver
server$ mkdir gitvarasto; cd gitvarasto/
server$ git init --bare --shared
$ exit


Then I made my local copy sync with the server

$ git remote add origin ssh://myname@ipofmyserver/home/myname/gitvarasto
$ git push origin master 
$ git branch --set-upstream master origin/master 
$ git pull && git push

As we can see my virtualbox computer's Git is set to use ssh to connect raspberryPi


Now just work normally with the files 

$ git pull && git push  
edit some files
$ git add . && git commit
$ git pull && git push

Then I opened my laptop, made a new folder and cloned the files from server

$ git clone ssh://myname@ipofmyserver/home/myname/gitvarasto

It copied all the files I have been working on other computer, nice. I also tried to edit a file on my laptop, then committed it and from virtualbox: $ git pull && git push and it synchronized.


And from giggle we can see nice graphical history what has happened. Who has modified the files and short log.


Ei kommentteja:

Lähetä kommentti