| 1 | [[PageOutline]] |
| 2 | = Version Control with ''git'' = |
| 3 | |
| 4 | Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. |
| 5 | |
| 6 | To use git on Cypress, you have to load module. It is better to set this in ''.modulerc'' (see below). |
| 7 | {{{#!bash |
| 8 | [fuji@cypress2 ~]$ module load git |
| 9 | }}} |
| 10 | |
| 11 | [[Image(GIT_model.png)]] |
| 12 | |
| 13 | == Create a project repository == |
| 14 | On your project directory, for example, (replace dpg with your project folder name) |
| 15 | {{{#!bash |
| 16 | [fuji@cypress2 fuji]$ cd projectX |
| 17 | [fuji@cypress2 projectX]$ git init |
| 18 | Initialized empty Git repository in /lustre/project/dpg/fuji/projectX/.git/ |
| 19 | }}} |
| 20 | |
| 21 | Add a file and commit |
| 22 | {{{#!bash |
| 23 | [fuji@cypress2 projectX]$ echo "This is README.txt for my git-repo" > README.txt |
| 24 | [fuji@cypress2 projectX]$ git add README.txt |
| 25 | [fuji@cypress2 projectX]$ git commit -m"first commit" |
| 26 | [master (root-commit) 4fe9eae] first commit |
| 27 | Committer: Hideki Fujioka <fuji@cypress2.cm.cluster> |
| 28 | Your name and email address were configured automatically based |
| 29 | on your username and hostname. Please check that they are accurate. |
| 30 | You can suppress this message by setting them explicitly. Run the |
| 31 | following command and follow the instructions in your editor to edit |
| 32 | your configuration file: |
| 33 | |
| 34 | git config --global --edit |
| 35 | |
| 36 | After doing this, you may fix the identity used for this commit with: |
| 37 | |
| 38 | git commit --amend --reset-author |
| 39 | |
| 40 | 1 file changed, 1 insertion(+) |
| 41 | create mode 100644 README.txt |
| 42 | }}} |
| 43 | |
| 44 | You can work with this repository on Cypress. |
| 45 | |
| 46 | === Create a Bare Repository === |
| 47 | If you want to make a git server repository, you have to make a Bare Repository. For example, |
| 48 | |
| 49 | {{{#!bash |
| 50 | [fuji@cypress2 dpg]$ mkdir repos |
| 51 | [fuji@cypress2 dpg]$ cd repos |
| 52 | [fuji@cypress2 repos]$ git clone --bare ../fuji/projectX ./projectX.git |
| 53 | }}} |
| 54 | |
| 55 | Add group write permissions to a repository so that people in your group can pull/push. |
| 56 | {{{#!bash |
| 57 | [fuji@cypress2 repos]$ chgrp -R dpg projectX.git |
| 58 | [fuji@cypress2 repos]$ chmod -R g+swX projectX.git |
| 59 | [fuji@cypress2 repos]$ cd projectX.git |
| 60 | [fuji@cypress2 projectX.git]$ git init --bare --shared |
| 61 | Reinitialized existing shared Git repository in /lustre/project/dpg/repos/projectX.git/ |
| 62 | }}} |
| 63 | |
| 64 | === Make a Clone Repository === |
| 65 | Make a clone repository on Cypress, |
| 66 | {{{#!bash |
| 67 | [fuji@cypress2 ~]$ git clone file:///lustre/project/dpg/repos/git/projectX.git |
| 68 | Cloning into 'projectX'... |
| 69 | remote: Counting objects: 3, done. |
| 70 | remote: Total 3 (delta 0), reused 0 (delta 0) |
| 71 | Receiving objects: 100% (3/3), done. |
| 72 | Checking connectivity... done. |
| 73 | [fuji@cypress2 ~]$ ls |
| 74 | projectX |
| 75 | }}} |
| 76 | |
| 77 | Make a clone repository over network, (you may have to type password) |
| 78 | {{{#!bash |
| 79 | Hideki02:~ fuji$ git clone fuji@cypress1.tulane.edu:/lustre/project/dpg/repos/git/projectX.git |
| 80 | Cloning into 'projectX'... |
| 81 | remote: Counting objects: 3, done. |
| 82 | remote: Total 3 (delta 0), reused 0 (delta 0) |
| 83 | Receiving objects: 100% (3/3), done. |
| 84 | Checking connectivity... done. |
| 85 | Hideki02:~ fuji$ ls |
| 86 | projectX |
| 87 | }}} |
| 88 | Since git is not a default module on Cypress, you have to set '''~/.modulerc''' like: |
| 89 | {{{#!bash |
| 90 | #%Module3.2.10 |
| 91 | module load git |
| 92 | }}} |
| 93 | |
| 94 | |
| 95 | == Free Git Repository == |
| 96 | * [https://bitbucket.org/] |
| 97 | * [https://github.com/] |
| 98 | |
| 99 | |
| 100 | == Basic Commands == |
| 101 | |
| 102 | === Add new files === |
| 103 | {{{#!bash |
| 104 | Hideki02:projectX fuji$ git add test.txt |
| 105 | }}} |
| 106 | This command updates the index using the current content found in the working tree, to prepare the content staged for the next commit. |
| 107 | |
| 108 | === Commit === |
| 109 | {{{#!bash |
| 110 | Hideki02:projectX fuji$ git commit -m"message" |
| 111 | }}} |
| 112 | Stores the current contents of the index in a new commit along with a log message from the user describing the changes. At this point, only your local clone has your modification. |
| 113 | |
| 114 | === push === |
| 115 | When you have your project at a point that you want to share with your group people, you have to push it to a master repository. |
| 116 | {{{#!bash |
| 117 | Hideki02:projectX fuji$ git push |
| 118 | }}} |
| 119 | You may have to type password for Cypress. |
| 120 | |
| 121 | === pull === |
| 122 | To pull current project in the master repository, |
| 123 | {{{#!bash |
| 124 | Hideki02:projectX fuji$ git pull |
| 125 | }}} |
| 126 | |
| 127 | == Documents == |
| 128 | * [https://git-scm.com/doc] |