divzeroweb

2f30.org website
git clone git://git.2f30.org/divzeroweb
Log | Files | Refs | README | LICENSE

git.md (3995B)


      1 ### Simple git guide for CVS users
      2 
      3 #### 0x0. Set up your user name + email.
      4 
      5 	$ git config --global user.name "you"
      6 	$ git config --global user.email "you@yourserver.org"
      7 	$ git config --global push.default simple
      8 
      9 This will create ~/.gitconfig.
     10 
     11 #### 0x1. Centralized workflow - basic notions
     12 
     13 Git avoids  touching the network as  much as possible.  The  few basic
     14 commands that require network access are as shown below.
     15 
     16 	* git-clone(1) # clone a repo for the first time
     17 	* git-push(1)  # push your branch
     18 	* git-pull(1)  # fetch compressed deltas and merge into current branch
     19 
     20 In git you  can have tracked and  untracked files.  In git  you have 3
     21 types of  changes.  If you modify  a tracked file you  have *modified*
     22 the file.  When  you do git-add(1) you  stage the file.  Finally
     23 with git-commit(1) you commit your change into your local branch.
     24 
     25 Staging is  important if you have  modified one or many  files and you
     26 want to  select a subset  of those changes  to commit.  This  makes it
     27 easy to break down your patches  and organize them as needed.  Ideally
     28 each patch is  useful on its own and unrelated  changes are grouped in
     29 separate  patches.  For  more  information  look at  the  -p flag  for
     30 git-add(1).
     31 
     32 For more advanced  operations you should *always* know  what state git
     33 is in.   You can  query that  with git-status(1).  If  you are  in the
     34 middle of a  merge and you forgot about it,  git-status(1) will remind
     35 you.  Use git-status(1) frequently.
     36 
     37 #### 0x2. Centralized git workflow
     38 
     39 To clone a repo:
     40 
     41 	$ git clone you@yourserver.org:myrepo.git
     42 
     43 To update your repo:
     44 
     45 	$ git pull
     46 
     47 	If you have local changes  the fetch/merge will proceed as expected.
     48 	You can  retain your local changes  even if they are  not committed.
     49 	If you have a merge conflict,  resolve it by hand and use git-add(1)
     50 	and git-commit(1).  The  history will continue to be  linear in case
     51 	of a fast-forward merge.
     52 
     53 To look at the commit history and the contents of each patch:
     54 
     55 	$ git log -p
     56 
     57 To commit your changes:
     58 
     59 	$ git commit -am 'Initial import'
     60 
     61 	This will  add all modified/deleted  files and commit  them locally.
     62 	New files are not added.
     63 
     64 To add new files/directories:
     65 
     66 	$ git add <file|dir>
     67 	$ git commit -m 'awesome'
     68 
     69 To push your changes to the remote branch:
     70 
     71 	$ git push
     72 
     73 To push a specific branch:
     74 
     75 	$ git push origin mybranch
     76 
     77 To show a diff between your modified files and the HEAD commit in your branch:
     78 
     79 	$ git diff
     80 
     81 To show the staged changes (the changes to be committed upon git-commit(1)):
     82 
     83 	$ git diff --cached
     84 
     85 To unstage changes:
     86 
     87 	$ git reset <file|dir>
     88 
     89 To remove a tracked file/dir:
     90 
     91 	$ git rm -r <file|dir>
     92 
     93 	This will also stage the change.  You can just git-commit(1) at this point.
     94 
     95 To rename a tracked file/dir:
     96 
     97 	$ git mv <src> <dst>
     98 
     99 	This will also stage the change.  You can just git-commit(1) at this point.
    100 
    101 To revert a modified file/dir to whatever is in HEAD:
    102 
    103 	$ git checkout <file|dir>
    104 
    105 To change the contents of your last commit:
    106 
    107 	$ # change files
    108 	$ git add <files>
    109 	$ git commit --amend
    110 
    111 To generate git patch files:
    112 
    113 	$ git format-patch -1
    114 
    115 	This will generate the patch file for the last commit.  You
    116 	can use git format-patch -<n> for the last *n* commits.
    117 
    118 To apply a git patch file:
    119 
    120 	$ git am mypatch.patch
    121 
    122 For a simple workflow you can avoid using the staging area completely.
    123 Just use the -am option for  git-commit(1) so you can stage and commit
    124 everything in one step.
    125 
    126 #### 0x3. Set up a server-side bare repo for your project
    127 
    128 To create a new repo in your home directory:
    129 
    130 	$ cd
    131 	$ cp -r /tmp/myproject myrepo
    132 	$ cd myrepo
    133 	$ git init
    134 	Initialized empty Git repository in /home/you/myrepo/.git/
    135 	$ git add *
    136 	$ git commit -m 'Initial import'
    137 	$ cd
    138 	$ # We do not need an unpacked repo, just a bare one
    139 	$ # no need to waste disk space
    140 	$ git clone --bare myrepo myrepo.git
    141 	$ rm -rf myrepo
    142 
    143 Assuming your  ssh-keys are in  place, you can now  clone myrepo.git
    144 just by doing:
    145 
    146 	$ git clone you@yourserver.org:myrepo.git
    147 
    148 bye!
    149 
    150 sin@