首次配置GITHUB环境
git config --global user.name "用户名"
git config --global user.email "邮箱名"
配置信息
git config --list
显示当前目录
pwd
清空界面
clear
进入下一级目录
cd 路径名
初始化GIT仓库,会在该目录生成一个.GIT隐藏文件夹
git init
新建文件
touch xxx.后缀名
暂存区状态(红色为未添加,绿色已添加)
git status
向暂存区添加文件
git add 文件名或git add .
将暂存区提交到本地仓库
git commit -m "备注信息"
修改文件
vi 文件名
从本地仓库删除文件
rm -rf 文件名
git rm 文件名
git commit -m "删除仓库文件"
关联远程仓库
git remote add origin git@github.com:ColorGalaxy/TPPRollingBall.git
将本地仓库上传到远程仓库
git push -u origin master
新建远程仓库并第一次推送 master 分支时,加上 -u 参数,Git 不但会把本地的 master 分支内容推送的远程新的 master 分支,还会把本地的 master 分支和远程的 master 分支关联起来,此后提交代码可以省去该参数,即git push origin master
撤销ADD的所有文件
git rm -r --cached .
克隆(远程仓库复制到本地)
git clone 仓库地址
报错1
$ git push -u origin master
To git@github.com:TaylorApril/test.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:TaylorApril/test.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解决办法:
git pull --rebase origin master
git push -u origin master
报错2
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
解决办法:
git push
报错3
$ git push -u origin master
To github.com:ColorGalaxy/TPPRollingBall.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:ColorGalaxy/TPPRollingBall.gi
t'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
原因:
刚才在网站上改了README.md文件,添加了一些项目的说明,然后使用Git命令再次提交的时候,需要先更新服务器上的变化,然后才能提交,也就是先更新再提交。
解决办法:
git pull