docs

docs and guides
git clone git://git.2f30.org/docs
Log | Files | Refs

simple-git (4221B)


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