| 
  
   Size: 1122 
  
  Comment:  
 | 
  
   Size: 4282 
  
  Comment:  
 | 
| Deletions are marked like this. | Additions are marked like this. | 
| Line 6: | Line 6: | 
| == SSH public key generation == * ls ~/.ssh * ssh-keygen # create ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub keys * cat ~/.ssh/id_rsa.pub # shows key to be sent to the git server admin == Config == * git config --global user.name "John Doe" * git config --global user.email johndoe@example.com * git config --list == Local config for repository == * git config user.name "John Doe" * git config user.email johndoe@example.com * git config --local --list * cat .git/config # [user] == Create repository == * cd <project> * git init #create folder .git * touch README.md * touch .gitignore * git add . * git commit -m 'Initial commit' * git remote add origin git@gitserver:/opt/git/project.git # setup origin for repository * git push origin master Edit .gitignore #for Java * *.jar * *.war * *.ear * *.zip Sample .gitignore {{{ *~ .metadata *.class *.jar *.war *.ear *.zip target/ }}} == Clone repository == * git clone git@git.server.net:repository.git # by ssh * git clone https://git.server.net/repository.git #by https * cd repository  | 
|
| Line 8: | Line 58: | 
| * git checkout -b B/20130801/BRANCH-XYZ master # create new branch base on branch master | * git checkout -b B/20130801/BRANCH-XYZ master # create new branch based on branch master | 
| Line 20: | Line 70: | 
| * git pull origin master # sync dest branch | |
| Line 29: | Line 80: | 
= Setup git server on RHEL = http://git-scm.com/book/en/Git-on-the-Server-Setting-Up-the-Server {{{#!highlight bash sudo bash adduser git su git cd mkdir .ssh cd .ssh git --version # git version 1.7.1 #generate and paste the pub key from my user on local machine ssh-keygen -f id_rsa -p cat ~/.ssh/id_rsa.pub #local machine # in the git server cd .ssh # git account vim authorized_keys #git server, paste the content of id_rsa.pub cd ~ chmod 700 .ssh/ chmod 600 .ssh/authorized_keys ssh git@bitarus.allowed.org # test connection from local machine vim /etc/passwd #change shell for git user git:x:505:505::/home/git:/usr/bin/git-shell # create project on git server cd /home/git mkdir hello.git cd hello.git git --bare init #create project on local machine cd ~ cd gitRepository mkdir hello cd hello git init touch README git add . git commit -m 'initial commit' git config --list #check config git remote add origin git@bitarus.allowed.org:/home/git/hello.git git push origin master git log }}} == Revert file to original == * git checkout -- testFile.txt == Github change from https to ssh == * git remote -v # check current remote repository * git remote set-url origin git@github.com:user/project.git == Delete local branch development and checkout remote development branch == * git branch -d development * git checkout -b development origin/development # get local branch from remote branch == Switch between branches == * git checkout development * git branch # check current branch * git checkout master * git branch # check current branch == Get remote branch to local branch == * git checkout -b wiki origin/wiki # local branch wiki from remote origin/wiki == Revert to HEAD revision == * git reset --hard HEAD == Make colors show properly on git diff and git log == * git config --global core.pager 'less -R' == Change commit message before a push == * git commit --amend  | 
git
Git is a distributed version control and source code management (SCM) system.
SSH public key generation
- ls ~/.ssh
 - ssh-keygen # create ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub keys
 - cat ~/.ssh/id_rsa.pub # shows key to be sent to the git server admin
 
Config
- git config --global user.name "John Doe"
 git config --global user.email johndoe@example.com
- git config --list
 
Local config for repository
- git config user.name "John Doe"
 git config user.email johndoe@example.com
- git config --local --list
 - cat .git/config # [user]
 
Create repository
cd <project>
- git init #create folder .git
 - touch README.md
 - touch .gitignore
 - git add .
 - git commit -m 'Initial commit'
 - git remote add origin git@gitserver:/opt/git/project.git # setup origin for repository
 - git push origin master
 
Edit .gitignore #for Java
- *.jar
 - *.war
 - *.ear
 - *.zip
 
Sample .gitignore
*~ .metadata *.class *.jar *.war *.ear *.zip target/
Clone repository
git clone git@git.server.net:repository.git # by ssh
git clone https://git.server.net/repository.git #by https
- cd repository
 
Branch creation based on current branch
- git branch #show current branch
 - git checkout -b B/20130801/BRANCH-XYZ master # create new branch based on branch master
 - git branch -m B/20130801/BRANCH-XYZ B/20130801/BRANCH-ZZZ # rename local branch
 - git push origin B/20130801/BRANCH-ZZZ # push branch B/20130801/BRANCH-ZZZ to remote
 
Commit to remote branch
- git commit -am 'Message commit xyz ' --all #commit locally
 - git pull origin B/20130801/BRANCH-ZZZ # sync with remote branch # fix conflicts and commit conflict resolution
 - git push origin B/20130801/BRANCH-ZZZ # send changes to remote branch
 
Merge to other branch
- git checkout master # merge destination branch
 - git pull origin master # sync dest branch
 - git merge --no-ff B/20130801/BRANCH-ZZZ # merge branch B/20130801/BRANCH-ZZZ to branch master
 - git pull origin master
 - git push origin master
 
Reapply .gitignore
cd <projectFolder>
- git rm -r -f --cached .
 - git add .
 - git status #check files to be commited
 
Setup git server on RHEL
http://git-scm.com/book/en/Git-on-the-Server-Setting-Up-the-Server
   1 sudo bash 
   2 adduser git
   3 su git
   4 cd
   5 mkdir .ssh
   6 cd .ssh
   7 git --version # git version 1.7.1
   8 
   9 #generate and paste the pub key from my user on local machine
  10 ssh-keygen -f id_rsa -p
  11 cat ~/.ssh/id_rsa.pub #local machine
  12 
  13 # in the git server
  14 cd .ssh # git account
  15 vim authorized_keys  #git server, paste the content of id_rsa.pub
  16 cd ~
  17 chmod 700 .ssh/
  18 chmod 600 .ssh/authorized_keys 
  19 ssh git@bitarus.allowed.org # test connection from local machine
  20 vim /etc/passwd #change shell for git user
  21 git:x:505:505::/home/git:/usr/bin/git-shell 
  22 
  23 # create project on git server
  24 cd /home/git
  25 mkdir hello.git
  26 cd hello.git
  27 git --bare init
  28 
  29 #create project on local machine
  30 cd ~
  31 cd gitRepository
  32 mkdir hello
  33 cd hello
  34 git init
  35 touch README
  36 git add .
  37 git commit -m 'initial commit'
  38 git config --list #check config
  39 git remote add origin git@bitarus.allowed.org:/home/git/hello.git
  40 git push origin master
  41 git log
Revert file to original
- git checkout -- testFile.txt
 
Github change from https to ssh
- git remote -v # check current remote repository
 git remote set-url origin git@github.com:user/project.git
Delete local branch development and checkout remote development branch
- git branch -d development
 - git checkout -b development origin/development # get local branch from remote branch
 
Switch between branches
- git checkout development
 - git branch # check current branch
 - git checkout master
 - git branch # check current branch
 
Get remote branch to local branch
- git checkout -b wiki origin/wiki # local branch wiki from remote origin/wiki
 
Revert to HEAD revision
- git reset --hard HEAD
 
Make colors show properly on git diff and git log
- git config --global core.pager 'less -R'
 
Change commit message before a push
- git commit --amend
 
