| 1 | This is a git project only used for test. |
|---|
| 2 | |
|---|
| 3 | Git Web Browse |
|---|
| 4 | http://ccode.ihep.ac.cn/git |
|---|
| 5 | |
|---|
| 6 | I. Git Configure |
|---|
| 7 | 1. Needed |
|---|
| 8 | git config --global user.name 'yourname' |
|---|
| 9 | git config --global user.email 'yourname@email.server' |
|---|
| 10 | 2. Optional |
|---|
| 11 | git config [--global] core.editor vim |
|---|
| 12 | git config [--global] core.paper 'less -N' |
|---|
| 13 | git config [--global] color.diff true |
|---|
| 14 | git config [--global] alias.co checkout |
|---|
| 15 | you can use 'git var -l' to list git configure. |
|---|
| 16 | |
|---|
| 17 | II. Clone Remote Repository to Local |
|---|
| 18 | git clone git@ccode.ihep.ac.cn:git-test-project.git |
|---|
| 19 | |
|---|
| 20 | III. Commit to Repository |
|---|
| 21 | 0. Show modified file |
|---|
| 22 | git rm file |
|---|
| 23 | git ls-files -m |
|---|
| 24 | |
|---|
| 25 | 1. Add changes |
|---|
| 26 | git add . |
|---|
| 27 | |
|---|
| 28 | 2. Commit to Local Repository |
|---|
| 29 | git commit -a -m 'your commit message' |
|---|
| 30 | or |
|---|
| 31 | git commit -a -e |
|---|
| 32 | |
|---|
| 33 | 3. Push to Remote Repository |
|---|
| 34 | git push |
|---|
| 35 | or |
|---|
| 36 | git push origin master |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | IV. Update Local Repository |
|---|
| 40 | 1. List remote repositories |
|---|
| 41 | git remote -v |
|---|
| 42 | |
|---|
| 43 | 2. Get latest version from remote to local |
|---|
| 44 | git fetch [repository] [branch] |
|---|
| 45 | Exmaple: |
|---|
| 46 | git fetch origin master |
|---|
| 47 | It means download updates from master branch of remote origin repository |
|---|
| 48 | to master branch of local origin repository |
|---|
| 49 | |
|---|
| 50 | 3. Compare differences between local and remote repository |
|---|
| 51 | git log -p master.. origin/master |
|---|
| 52 | |
|---|
| 53 | 4. Merge remote to local |
|---|
| 54 | git merge origin/master |
|---|
| 55 | |
|---|
| 56 | V. Local Branch |
|---|
| 57 | 1. List remote branches |
|---|
| 58 | git remote -v |
|---|
| 59 | |
|---|
| 60 | 2. Check out remote branch as a new branch to local |
|---|
| 61 | git fetch origin master:temp |
|---|
| 62 | |
|---|
| 63 | 3. Compare differences between origin branch and local branch |
|---|
| 64 | git diff temp |
|---|
| 65 | |
|---|
| 66 | 4. Merge other branch to master branch |
|---|
| 67 | git merge temp |
|---|
| 68 | |
|---|
| 69 | 5. Delete branch |
|---|
| 70 | git branch -d temp |
|---|
| 71 | You can force to delete a branch withou merging to master branch: |
|---|
| 72 | git branch -D temp |
|---|
| 73 | |
|---|
| 74 | |
|---|