创建github库,如下图:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#通常都默认安装了git,如果没有安装 sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel sudo yum install git #查看帮助 git help #配置文件 /etc/gitconfig //针对系统中所有用户的配置,若使用 git config 时用--system 选项,读写的就是这个文件。 ~/.gitconfig //针对某一用户的配置,若使用git config 时用–global 选项,读写的就是这个文件。 .git/config //当前项目的git目录中的配置文件,这里的配置仅仅针对当前项目有效。 #基本配置 git config --global user.name "txf19870527" //用户名 git config --global user.email "223738367@qq.com" //邮箱 git config --global core.editor vim //默认编辑器 git config --global merge.tool vimdiff //默认冲突解决工具 git config --list //查看所有配置,可通过vim直接查看 #常见错误 #如果git push报403错误,修改项目目录下的.git/config 将url修改为@那种写法 [remote "origin"] url = https://github.com/txf19870527/composer-test.git [remote "origin"] url = https://txf19870527@github.com/txf19870527/composer-test.git # 创建项目并提交到github mkdir composer-test cd composer-test echo "# composer-test" >> README.md git init git add README.md git commit -m "first commit" # 提交到本地 git remote add origin git@github.com:txf19870527/composer-test.git # 设置github源 git push -u origin master # 提交到github |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#安装全局composer,如果ssl报错,把https改成http curl -sS https://getcomposer.org/installer | php #如果https http 都不行 php -r 安装 php -r "readfile('https://getcomposer.org/installer');" | php #将composer设置成全局命令 mv composer.phar /usr/local/bin/composer composer init Package name (<vendor>/<name>) [root/composer-json]: bestlove/composer-json # 填写项目名称 Description []: this is a composer test # 描述 Author [txf19870527 <223738367@qq.com>]: # 作者 默认 Minimum Stability []: # 默认 Package Type []: # 默认 License []: MIT # 开源协议 Would you like to define your dependencies (require) interactively [yes]? no # 是否需要依赖包 Would you like to define your dev dependencies (require-dev) interactively [yes]? no # 是否需要开发依赖包 Do you confirm generation [yes]? # 确认 Would you like the vendor directory added to your .gitignore [yes]? # git忽略项 |
访问https://packagist.org -> submit 进行设置 如下图:
在github添加hook,使提交自动同步到packagist 如下图:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 在刚才初始化的composer.json中添加自动加载规则 vim composer.json "autoload": { "psr-4": { "Bestlove\\ComposerTest\\": "src" } } mkdir src cd src vim Test.php <?php namespace Bestlove\ComposerTest; class Test { public function say() { echo 'hello world'; } } # push到github后会自动同步到https://packagist.org # 此时 我们就能通过 compoesr 下载了 composer require bestlove/composer-test dev-master vim index.php <?php require __DIR__ . '/vendor/autoload.php'; $test = new Bestlove\ComposerTest\Test(); $test->say(); |
1 2 3 4 5 6 7 8 9 |
#刚刚创建项目使用的命令是:composer require bestlove/composer-test dev-master #不能去掉dev-master 表示正在开发阶段,还未正式发布,需要打包完才能去掉 #创建分支并打包 git checkout -b 0.1 #创建并切换到0.1分支 git push origin 0.1 #推送到github git branch #查看分支情况 git tag 0.1.0 #根据0.1分支,创建tag git push --tags #推送tag到github |