Thursday, August 13, 2015

GIT tutorial



Tutorial: 

http://gitready.com/
http://blog.osteele.com/posts/2008/05/my-git-workflow/

Basic structure







Image from: From : http://blog.osteele.com/posts/2008/05/my-git-workflow/

Following tips are collected from CBRC git (Thanks to John and Craig)
Original LInk: http://dragon.cbrc.kaust.edu.sa/wiki/index.php/Cbrcgit

Cbrcgit

Jump to: navigation, search

Contents

What is git

http://en.wikipedia.org/wiki/Git_%28software%29
Git is a free distributed revision control, or software source code management, project with an emphasis on being fast. Git was initially designed and developed by Linus Torvalds for Linux kernel development.
Every Git working directory is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server.
Git has a very powerfull command and option set. Some defaults need to be set in new projects to streamline the workflow.

CBRC git server

The central git server for CBRC runs at git.cbrc.kaust.edu, or if you want to use a friendlier GitLab version, have a look at Gitlab wiki.
Also, notice that in communications with the cbrcgit server, everyone should be using the 'git' username. This minimizes the chances of having conflicts with different users creating files in the server.
To access the server, you need to send the CBRC IT support your public ssh key (~/.ssh/id_rsa.pub). If your work computer does not have one, you can generate it:
 $  ssh-keygen -t rsa # with an empty pass phrase
You can find more info about this on FAQ pages.

Quick start

  • On your development computer (provided that git has been installed):
$ cd <my_project_directory>
$ git init
$ git config user.name 'My Name'
$ git config user.email 'My Email Address'
$ git remote add origin ssh://git@git.cbrc.kaust.edu.sa/datapool/git/datagit/My_Project_Name.git/
  • Login to the CBRC git repository and create your project.
$ ssh git@git.cbrc.kaust.edu.sa
$ mkdir /datapool/git/datagit/My_Project_Name.git
$ cd /datapool/git/datagit/My_Project_Name.git
$ git --bare init
$ vim description
$ exit
  • Back on your development machine, add files to the local and remote repository: 
A. Make your local version integrate all from server
$ git pull ssh://git@git.cbrc.kaust.edu.sa/datapool/git/datagit/LDmotif.git
 
B . Now upload your changes to server 

$ git add -A
$ git commit -am 'note about the commit'
$ git push origin master
Please do not forget to edit description file. 3 lines are enough, but you can add more:
   project name
   web location or short description
   contact

Using git

Start by telling git your contact details:
 $ git config --global user.name "Your Name"
 $ git config --global user.email "your.name@kaust.edu.sa"
Since git is a distributed version controlling system, you can use it for any directory. Simply run:
 $ git init
After that you can add subdirectories and files and modify existing ones. Note that git commit command takes note of only those files that have been 'add'ed.
 $ git add .
 $ git commit -a -m 'note about the commit'
Git contains powerful mechanisms to branch, merge versions and study older versions.
Important: If you want to rename a file or directory that is under git, do not use the normal 'mv' command. Git can keep track of the change, if you do:
 $ git mv filename newfilename
Similarly, remove a file from disk and git at the same time:
 $ git rm filename
Committing to a remote git: The latest git does not allow you to commit before you select the push method. The following command sets it globally for all your git repositories:
 $ git config --global push.default matching

See: man pages git, gittutorial


Creating a new remote repository

Once your public ssh key is installed on the git machine (see the procedure in the previous chapter), you can add a new project, e.g. 'myproj', into the git server.
 $ ssh git@git.cbrc.kaust.edu.sa
 $ mkdir /datapool/git/datagit/myproj.git
 $ cd /datapool/git/datagit/myproj.git
 $ git --bare init
 Initialized empty Git repository in /datapool/git/datagit/myproj.git/
 $ exit
Note that this remote directory name needs to end '.git' for the connection to work.

Creating a new local git repository

You can create a local git repository and start using it to keep track of changes a few simple commands:
 $ mkdir myproj
 $ cd myproj/
 $ git --bare init
 # add files and content, e.g.:
 $ echo "text" > readme
 # tell git not to keep track of backup files, e.g. 
 $ echo '*~' > .gitignore
 # tell git to track all files and commit them for the first time
 $ git add .
 $ git commit -a -m 'first commit'
The local git repository sits on your machine and reflects all changes in your files after you commit them. Remember, therefore: the commit command does not update anything outside of your machine (as it does with few others version control systems). If you need to share your project and its files with others, you need to propagate your changes to the CBRC central git server. Read on.

These following commands are needed only when you want to link the local to the CBRC central server:
 $ git remote add origin ssh://git@git.cbrc.kaust.edu.sa/datapool/git/datagit/myproj.git
 $ git push origin master
 

Very important command to let git know using master branch

 
# tell git that by default you are working on the head of the master
 # branch in the remote repository
 $ git config branch.master.remote origin
 $ git config branch.master.merge refs/heads/master

Other CBRC members (who have their public ssh keys installed - see above) can now download their copy of the project with:
 $ git clone ssh://git@git.cbrc.kaust.edu.sa/datapool/git/datagit/myproj.git
From there on, before working on the project, you should first check if someone has update the central repository:
 $ git pull
 # After setting the defaults above, this is same as:
 $ git pull ssh://git@git.cbrc.kaust.edu.sa/datapool/git/datagit/myproj.git master
While working with files, you can check the status any time with:
 $ git status
 $ git log (filename)
 $ git diff filename
 $ git blame filename
and commit any changes in logical sets.
After working with a set of tasks, you should push the changes to the central repository for others to see:
 $ git push origin master

Project repository

The current git repository location is: git@git.cbrc.kaust.edu.sa:/datapool/git/datagit/
CBRC Git repository browser: http://dragon.cbrc.kaust.edu.sa/cbrcwg/

See also

Best Tutorial


http://classic.scottr.org/presentations/git-in-5-minutes/

1. CREATE : ## Make a REMOTE repository in server as git repository

 

  •  On your git  server machine

$ ssh git@git.cbrc.kaust.edu.sa
$ mkdir /datapool/git/datagit/My_Project_Name.git
$ cd /datapool/git/datagit/My_Project_Name.git
$ git --bare init
Initialized empty Git repository in /datapool/git/datagit/myproj.git/
$ vim description $ exit

2. CREATE :  ## Make a LOCAL repository and upload to git repository

  •  On your development computer (provided that git has been installed):
$ cd <my_local_project_directory>
$ git --bare init
$ git config user.name 'My Name'
$ git config user.email 'My Email Address'
$ git remote add origin ssh://git@git.cbrc.kaust.edu.sa/datapool/git/datagit/My_Project_Name.git/


  • add files to the local and remote repository:
$ git add -A
# tell git to track all files and commit them for the first time
$ git add .
$ git commit -am 'note about the commit' $ git push origin master



3. DOWNLOAD : ALREADY EXISTING git repository from server FIRST TIME



 

4. WORK : ALREADY EXISTING git repository


  • From there on, before working on the project, you should first check if someone has update the central repository:

 $ git pull
 # After setting the defaults above, this is same as:
 $ git pull ssh://git@git.cbrc.kaust.edu.sa/datapool/git/datagit/myproj.git master


  • While working with files, you can check the status any time with:

 $ git status
 $ git log (filename)
 $ git diff filename
 $ git blame filename

and commit any changes in logical sets.



  • After working with a set of tasks, you should push the changes to the central repository for others to see:

 $ git push origin master


If git is not sure which branch to use, use master

# tell git that by default you are working on the head of the master
 # branch in the remote repository
 $ git config branch.master.remote origin
 $ git config branch.master.merge refs/heads/master

 

5. Some useful commands

## Make local index from remote git index when you create git local index First time


git clone


## Show the remote git repository

git remote -v

## Download from git repository


git pull


## check difference between local file and local git index
git diff   file.html

## Commit locally
git commit -m "uploading a single file"  help.html
git commit -m "uploading all changes"  .

## Commit in server
git push

No comments:

Post a Comment