# 从 Git 上获得源代码

**URL:** <https://www.isharkfly.com/t/git/4420>\
**Category:** PHP\
**Created:** [August 28, 2013, 2:37am UTC](https://www.isharkfly.com/t/git/4420 "2013-08-28T02:37:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [August 28, 2013, 2:37am UTC](https://www.isharkfly.com/t/git/4420/1 "2013-08-28T02:37:49Z")

</div>

这里我们讨论 GIT 的命令行工具，Git 的图形化工具也基本上基于命令行，你应该比较容易的来获得正确的安装参数。

Moodle 的官方 Git 仓库链接如下： git://git.moodle.org/moodle.git 同时 Moodle 官方也会将代码推送到 github 中，你依然可以使用下面的链接git://github.com/moodle/moodle.git)。

使用下面的命令来初始化你本地的代码：`git clone git://git.moodle.org/moodle.git `例如当前目录是 /home/yuchenghu

在这个目录下，你执行`git clone git://git.moodle.org/moodle.git `命令，会在当前目录下创建一个名为 moodle 的目录。

服务器输出：`
[root@ca1 yuchenghu]# git clone git://git.moodle.org/moodle.git
Initialized empty Git repository in /home/yuchenghu/moodle/.git/
remote: Counting objects: 676955, done.
remote: Compressing objects: 100% (158836/158836), done.
remote: Total 676955 (delta 502896), reused 676955 (delta 502896)
Receiving objects: 100% (676955/676955), 247.96 MiB | 9.33 MiB/s, done.
Resolving deltas: 100% (502896/502896), done.
[root@ca1 yuchenghu]# dir
history.txt mantisbt rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
latest.zip moodle
[root@ca1 yuchenghu]#
`执行：`cd moodle`执行：`git branch -a `服务器输出：[code]  
[root@ca1 moodle]# git branch -a

- master  
remotes/origin/HEAD → origin/master  
remotes/origin/MOODLE\_13\_STABLE  
remotes/origin/MOODLE\_14\_STABLE  
remotes/origin/MOODLE\_15\_STABLE  
remotes/origin/MOODLE\_16\_STABLE  
remotes/origin/MOODLE\_17\_STABLE  
remotes/origin/MOODLE\_18\_STABLE  
remotes/origin/MOODLE\_19\_STABLE  
remotes/origin/MOODLE\_20\_STABLE  
remotes/origin/MOODLE\_21\_STABLE  
remotes/origin/MOODLE\_22\_STABLE  
remotes/origin/MOODLE\_23\_STABLE  
remotes/origin/MOODLE\_24\_STABLE  
remotes/origin/MOODLE\_25\_STABLE  
remotes/origin/master  
[root@ca1 moodle]#  
[/code]执行：`git branch --track MOODLE_25_STABLE origin/MOODLE_25_STABLE`服务器输出：`[root@ca1 moodle]# git branch --track MOODLE_25_STABLE origin/MOODLE_25_STABLE
Branch MOODLE_25_STABLE set up to track remote branch MOODLE_25_STABLE from origin.
[root@ca1 moodle]#
`执行：`git checkout MOODLE_25_STABLE`服务器输出：`[root@ca1 moodle]# git checkout MOODLE_25_STABLE
Switched to branch 'MOODLE_25_STABLE'
[root@ca1 moodle]#
`这时候已经切换了正确的分支了，并且代码已经在 moodle 的目录中了。

![](https://www.isharkfly.com/images/transparent.png)
