Posted to tcl by patthoyts at Wed Oct 01 21:25:07 GMT 2008view raw

  1. * Setting up
  2.  
  3. Make sure to configure git with your id.
  4. git config --global user.name "Pat Thoyts"
  5. git config --global user.email patthoyts@users.sourceforge.net
  6. (see the windows section too).
  7.  
  8. * Import a cvs repository into git
  9.  
  10. This is done using cvsps:
  11. cvs -d:local:/opt/mirror/tcludp co -d tcludp.cvs tcludp
  12. cd tcludp.cvs
  13. git cvsimport -k -C ../tcludp tcludp
  14.  
  15. * Windows configuration
  16.  
  17. On windows we want to use plink so set GIT_SSH=c:\opt\bin\plink.exe
  18. Ensure that on the server it will run git commands for non-interactive
  19. logins. On my Solaris box I had to add the path into /etc/default/login.
  20.  
  21. On Windows git prefers that EDITOR be a full path:
  22. set EDITOR=c:\opt\emacs-21.3\site-bin\gnuclientw.exe
  23.  
  24. To get proper line ending handling ' git config --global core.autocrlf true'
  25. then update all the files. For a repository that I had already
  26. checkout with unix line endings I deleted everything then did
  27. 'git reset --hard' but there might be a smarter method.
  28.  
  29. * Publishing a repository
  30.  
  31. On the server, create a bare repository:
  32. mkdir /opt/gitrepos/xyzzy && cd /opt/gitrepos/xyzzy
  33. git --bare init
  34. chmod +x hooks/post-update
  35. touch git-daemon-export-ok
  36. edit the description file to have a useful name.
  37.  
  38. On the dev machine, add the remote repository as 'origin'
  39. git remote add origin ssh://pat@cvs.patthoyts.tk/opt/gitrepos/xyzzy
  40. and configure as a tracking branch:
  41. git config branch.master.remote origin
  42. git config branch.master.merge refs/heads/master
  43.  
  44. Now you can push your code to origin from master
  45. git push origin master
  46. and pull later:
  47. git pull
  48.  
  49. * Publishing a local branch
  50.  
  51. On the remote site, create a bare repository:
  52. cd /opt/gitrepos
  53. mkdir gitk
  54. cd gitk
  55. git --bare init
  56. echo 'My gitk mods' > description
  57. back on your working machine:
  58. git remote mymods ssh://cvs.patthoyts.tk/opt/gitrepos/gitk
  59. git push mymods
  60. This configures a remote repository called 'mymods' and then we push our
  61. current branch to the named remote repository (as we are working on
  62. branch mybranch this creates a mybranch branch in the remote).
  63.  
  64. * Basic workflow
  65.  
  66. Edit files then add them to the index 'git add .' or 'git add filename'.
  67. Once the changeset is ready, 'git commit' it and write a decent
  68. message. The first line should be suitable for a one line description,
  69. then put more details in subsequent lines. Dont be shy after the
  70. first line. The first word of the first line tends to be some kind of
  71. keyword identifier.
  72. 'git rm filename' removes files (and marks the index appropriately)
  73. 'git mv filea fileb' renames files and sets up the index.
  74. 'git reset' undoes work from the index. So to junk uncommitted changes
  75. from the index, use 'git reset --hard'
  76. To switch to a branch, 'git checkout branchname'
  77. 'git diff' - see changes in working tree
  78. 'git diff branch' see changes between this and the named branch
  79.  
  80.  
  81. * Conflict resolution
  82.  
  83. If git fails to merge then git status will report the files as
  84. outstanding. Edit them to fix the problems (removing conflict markers)
  85. and then use 'git update-index filename' to update the index. Once
  86. you're done then you can 'git commit'.
  87.  
  88. * Log message editing
  89.  
  90. If the log message is messed up, 'git commit --amend' will let you
  91. edit the last commit message. Probably best done before any 'git push'.
  92. 'git commit -s --amend' will let you signoff the commit in case you
  93. didn't do that already.
  94.  
  95. * Branch merging
  96.  
  97. To cleanly move a patch branch up to the current head we use rebase
  98. So if we are on tip213, 'git rebase master' moves the branch point and
  99. reapplys the patches. If we run into merge problems and get conflicts
  100. then resolve them and use 'git rebase --continue'.
  101.  
  102. * Extending git with aliases
  103.  
  104. We can add some useful aliases quite easily. For instance, we can have
  105. 'git ci' be commit and 'git branches' list all branches.
  106.  
  107. 'git config --global alias.ci commit'
  108. 'git config --global alias.branches "branch -l"'