Difference between revisions of "Git"
From Healthcare Robotics Wiki
Advaitjain (Talk | contribs) (→Coverting a stack from svn to a git repository) |
Advaitjain (Talk | contribs) (→Clone from the internal server) |
||
| (29 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| − | == | + | == Tutorials == |
| + | * http://git-scm.com/documentation | ||
| + | |||
| + | == Tips and Tricks == | ||
| + | * [http://www.arthurkoziel.com/2008/05/02/git-configuration/ Initial setup] | ||
| + | * [http://help.github.com/ignore-files/ ignore files] | ||
| + | * GUIs: | ||
| + | *# gitk: | ||
| + | *#* sudo apt-get install gitk | ||
| + | *#* http://sitaramc.github.com/1-basic-usage/gitk.html#1_basic_usage_gitk_the_missing_gitk_documentation_ | ||
| + | *#* run gitk from within the git repository | ||
| + | *# git gui | ||
| + | *#* sudo apt-get install git-gui | ||
| + | |||
| + | === Customize your bash prompt === | ||
| + | |||
| + | ==== Show the branch name ==== | ||
| + | ===== Method 1 ===== | ||
| + | * The following steps allow you to have colored text at the command prompt for telling you which current branch you are using: | ||
| + | ** Download the script from [https://raw.github.com/git/git/master/contrib/completion/git-completion.bash/ here] and put in home directory | ||
| + | ** Add these lines to your .bashrc file: | ||
| + | ***source ~/git-completion.bash | ||
| + | ***export PS1='\[\e[36;1m\]\u@\[\e[32;1m\]\H:\[\e[0m\]\w\[\e[31;1m\]$(__git_ps1 "(\%s)")\[\e[0m\]>' | ||
| + | ****lots of this command is text coloring, see [http://www.pantz.org/software/shell/enhancingshellprompt.html/ this site] for details | ||
| + | **[[File:Git_colored_command_prompt.png|x414px]] - example of what this does | ||
| + | |||
| + | ===== Method 2 ===== | ||
| + | |||
| + | Add this to your bashrc: | ||
| + | |||
| + | function parse_git_branch { | ||
| + | git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | ||
| + | } | ||
| + | COLOR_NONE="\[\e[0m\]" | ||
| + | GREEN="\[\033[0;32m\]" | ||
| + | RED="\[\033[0;31m\]" | ||
| + | export PS1="[\u@\h \W]$RED\$(parse_git_branch)$COLOR_NONE\$ " | ||
| + | |||
| + | [[File:Git_prompt_advait.png]] | ||
| + | |||
| + | == Git Repositories for Internal Use== | ||
=== Motivation === | === Motivation === | ||
| − | * Advait would like to have | + | * Advait would like to have internal git repositories as well. |
| − | * The goal would be to use | + | * The goal would be to use these for active development and release by merging to a repo on gt-ros-pkg hosted on google code. |
=== Create a new git repository on internal server === | === Create a new git repository on internal server === | ||
| − | |||
| − | |||
# ssh mycroft@skynet | # ssh mycroft@skynet | ||
# cd internal_git_bare | # cd internal_git_bare | ||
| − | # | + | # mkdir test_repository |
| + | # cd test_repository | ||
| + | # git init | ||
| + | # touch .first | ||
| + | #* for some reason git doesn't like completely empty repositories | ||
| + | # git add .first | ||
| + | # git commit -m "initial dummy commit" | ||
# Convert to a bare repository using steps from [http://stackoverflow.com/questions/2816369/git-push-error-remote-rejected-master-master-branch-is-currently-checked here]: | # Convert to a bare repository using steps from [http://stackoverflow.com/questions/2816369/git-push-error-remote-rejected-master-master-branch-is-currently-checked here]: | ||
## cd hrl_haptic_manipulation_in_clutter/ | ## cd hrl_haptic_manipulation_in_clutter/ | ||
## git config --bool core.bare true | ## git config --bool core.bare true | ||
| − | ## rm -rf | + | ## rm -rf .first |
## ls -la | ## ls -la | ||
##* you should see a .git | ##* you should see a .git | ||
=== Steps on each client machine === | === Steps on each client machine === | ||
| + | |||
==== Clone from the internal server ==== | ==== Clone from the internal server ==== | ||
# cd to whichever directory you want to keep your repo in. (e.g. cd ~/git) | # cd to whichever directory you want to keep your repo in. (e.g. cd ~/git) | ||
| − | # git clone mycroft@skynet.hsi.gatech.edu:/home/mycroft/internal_git_bare/ | + | # git clone mycroft@skynet.hsi.gatech.edu:/home/mycroft/internal_git_bare/hrl_haptic_manipulation_in_clutter |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | '''Cloning a specific branch''' | |
| − | # git | + | # git clone -b advaits_branch mycroft@skynet.hsi.gatech.edu:/home/mycroft/internal_git_bare/hrl_haptic_manipulation_in_clutter |
| − | # git checkout - | + | #* by doing this, I get only advaits_branch and not the master. |
| + | |||
| + | '''Pushing a branch to the internal git server''' | ||
| + | # git push origin advaits_new_branch | ||
| + | #* see http://gitready.com/beginner/2009/02/02/push-and-delete-branches.html | ||
| + | '''After pushing a branch:''' | ||
| + | # git branch -r | ||
| + | #* confirm that the branch show up as origin/advaits_new_branch | ||
| + | # git branch -d advaits_new_branch | ||
| + | #* delete the local branch. | ||
| + | # git checkout --track origin/advaits_new_branch | ||
| + | #* Check out and track the new remote branch | ||
| + | |||
| + | '''Checkout and track a new remote branch''' | ||
| + | # git checkout --track origin/advaits_new_branch | ||
| + | |||
| + | '''Adding a remote branch (from a different repo)''' | ||
| + | # git remote add -f <new_branch_name> <path_to_repo> | ||
==== To release code ==== | ==== To release code ==== | ||
| Line 42: | Line 101: | ||
#* put in an appropriate release message. | #* put in an appropriate release message. | ||
| − | === | + | |
| − | + | === Coverting a stack from svn to a git repository === | |
| + | # ssh mycroft@skynet | ||
| + | # cd internal_git_bare | ||
| + | # get a specific folder from svn and make a git repo out of it: <br> git svn clone https://svn.hsi.gatech.edu/cckemp/robot1/src/projects/hrl_haptic_manipulation_in_clutter | ||
| + | # Convert to a bare repository using steps from [http://stackoverflow.com/questions/2816369/git-push-error-remote-rejected-master-master-branch-is-currently-checked here]: | ||
| + | ## cd hrl_haptic_manipulation_in_clutter/ | ||
| + | ## git config --bool core.bare true | ||
| + | ## rm -rf * | ||
| + | ## ls -la | ||
| + | ##* you should see a .git | ||
==Old stuff == | ==Old stuff == | ||
| Line 63: | Line 131: | ||
# git merge google_code_master | # git merge google_code_master | ||
| + | ==== maybe useful commands? ==== | ||
| + | # git checkout --track origin/internal_hrl | ||
| + | #* now you will see two branches (master and internal_hrl) | ||
| + | #* usually Advait would expect people to work in the internal_hrl branch | ||
=== Create bare git repository on internal git server === | === Create bare git repository on internal git server === | ||
| Line 77: | Line 149: | ||
# git branch -m master internal_hrl | # git branch -m master internal_hrl | ||
#* rename master to internal_hrl | #* rename master to internal_hrl | ||
| + | |||
| + | ==== Add a remote branch to work directly with the google code repository ==== | ||
| + | # git remote add -f gt-ros-pkg.hrl_google_code https://code.google.com/p/gt-ros-pkg.hrl/ | ||
| + | # git checkout -b google_code_master gt-ros-pkg.hrl_google_code/master | ||
Latest revision as of 19:16, 6 May 2012
Contents |
[edit] Tutorials
[edit] Tips and Tricks
- Initial setup
- ignore files
- GUIs:
- gitk:
- sudo apt-get install gitk
- http://sitaramc.github.com/1-basic-usage/gitk.html#1_basic_usage_gitk_the_missing_gitk_documentation_
- run gitk from within the git repository
- git gui
- sudo apt-get install git-gui
- gitk:
[edit] Customize your bash prompt
[edit] Show the branch name
[edit] Method 1
- The following steps allow you to have colored text at the command prompt for telling you which current branch you are using:
- Download the script from here and put in home directory
- Add these lines to your .bashrc file:
- source ~/git-completion.bash
- export PS1='\[\e[36;1m\]\u@\[\e[32;1m\]\H:\[\e[0m\]\w\[\e[31;1m\]$(__git_ps1 "(\%s)")\[\e[0m\]>'
- lots of this command is text coloring, see this site for details
- example of what this does
[edit] Method 2
Add this to your bashrc:
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
COLOR_NONE="\[\e[0m\]"
GREEN="\[\033[0;32m\]"
RED="\[\033[0;31m\]"
export PS1="[\u@\h \W]$RED\$(parse_git_branch)$COLOR_NONE\$ "
[edit] Git Repositories for Internal Use
[edit] Motivation
- Advait would like to have internal git repositories as well.
- The goal would be to use these for active development and release by merging to a repo on gt-ros-pkg hosted on google code.
[edit] Create a new git repository on internal server
- ssh mycroft@skynet
- cd internal_git_bare
- mkdir test_repository
- cd test_repository
- git init
- touch .first
- for some reason git doesn't like completely empty repositories
- git add .first
- git commit -m "initial dummy commit"
- Convert to a bare repository using steps from here:
- cd hrl_haptic_manipulation_in_clutter/
- git config --bool core.bare true
- rm -rf .first
- ls -la
- you should see a .git
[edit] Steps on each client machine
[edit] Clone from the internal server
- cd to whichever directory you want to keep your repo in. (e.g. cd ~/git)
- git clone mycroft@skynet.hsi.gatech.edu:/home/mycroft/internal_git_bare/hrl_haptic_manipulation_in_clutter
Cloning a specific branch
- git clone -b advaits_branch mycroft@skynet.hsi.gatech.edu:/home/mycroft/internal_git_bare/hrl_haptic_manipulation_in_clutter
- by doing this, I get only advaits_branch and not the master.
Pushing a branch to the internal git server
- git push origin advaits_new_branch
After pushing a branch:
- git branch -r
- confirm that the branch show up as origin/advaits_new_branch
- git branch -d advaits_new_branch
- delete the local branch.
- git checkout --track origin/advaits_new_branch
- Check out and track the new remote branch
Checkout and track a new remote branch
- git checkout --track origin/advaits_new_branch
Adding a remote branch (from a different repo)
- git remote add -f <new_branch_name> <path_to_repo>
[edit] To release code
- create an appropriately named release branch.
- push that release branch to the internal server.
- create a new git repository on gt-ros-pkg for the stack to be released.
- clone this gt-ros-pkg repository to your computer.
- add internal repository as a remote branch on your computer's clone of gt-ros-pkg repo:
git remote add -f <release_stack_name> mycroft@skynet.hsi.gatech.edu:/home/mycroft/internal_git_bare/<release_stack_name> - perform a merge:
git merge <release_stack_name>/<release_branch> - optionally reset the history:
git reset --soft HEAD^ - git commit -a
- put in an appropriate release message.
[edit] Coverting a stack from svn to a git repository
- ssh mycroft@skynet
- cd internal_git_bare
- get a specific folder from svn and make a git repo out of it:
git svn clone https://svn.hsi.gatech.edu/cckemp/robot1/src/projects/hrl_haptic_manipulation_in_clutter - Convert to a bare repository using steps from here:
- cd hrl_haptic_manipulation_in_clutter/
- git config --bool core.bare true
- rm -rf *
- ls -la
- you should see a .git
[edit] Old stuff
- git checkout google_code_master
- git checkout internal_hrl <path to files to release>
- git commit -a
- type in some descriptive release message.
- git checkout internal_hrl
- switch back to the internal_hrl branch
- ssh to skynet and push to google code.
[edit] To get changes from google code repository
Merge the changes in the google_code_master branch with the internal_hrl branch
- git checkout google_code_master
- git pull
- git checkout internal_hrl
- git merge google_code_master
[edit] maybe useful commands?
- git checkout --track origin/internal_hrl
- now you will see two branches (master and internal_hrl)
- usually Advait would expect people to work in the internal_hrl branch
[edit] Create bare git repository on internal git server
- ssh skynet.hsi.gatech.edu -lmycroft
- mkdir internal_git_bare
- cd internal_git_bare
- Clone gt-ros-pkg with advait as the user on skynet.hsi.gatech.edu:
git clone https://advaitjain@code.google.com/p/gt-ros-pkg.hrl/ - Convert to a bare repository using steps from here:
- cd gt-ros-pkg.hrl/
- git config --bool core.bare true
- rm -rf *
- ls -la
- you should see a .git
- git branch -m master internal_hrl
- rename master to internal_hrl
[edit] Add a remote branch to work directly with the google code repository
- git remote add -f gt-ros-pkg.hrl_google_code https://code.google.com/p/gt-ros-pkg.hrl/
- git checkout -b google_code_master gt-ros-pkg.hrl_google_code/master