您的位置:首页 > 编程语言

向git提交代码及更新代码的命令

2015-08-24 10:25 387 查看

一、提交代码

(1)cd C:\Users\{{username}}\Desktop\{{filename}}

说明:若项目文件夹路径为C:\Users\{{username}}\Desktop\{{filename}},则{{username}}为操作系统的用户名,{{filename}}是你要提交代码的项目文件夹;路径也可以是其他的

(2)git init

说明:这是初始化在{{filename}}文件夹中建立一个空库

(3)git add

说明:这条命令有两种用法:git add . (注意add.之间有空格)用于把当前文件夹中的所有文件都加入到上传的列表中;git add "你要添加的文件(test.txt)"

(4)git commit -m "说明"

说明:这个"说明"可以自己随意写

(5)git remote add origin https://github.com/test/test.git
说明:origin 相当于是个别名  你可以不管它,也自己随便写或者写成当前文件夹名 , 后面的地址是你在github新建的仓库地址

(6)git push -u origin master

说明:此处的origin和(5)中的origin需保持一致。

注:

若执行第(6)步出现如下错误:

To https://github.com/test/test.git
 ! [rejected]        master -> master (fetch first)

error: failed to push some refs to 'https://github.com/test/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.

则使用如下命令代替第(6)步:

git push -f origin master

二、更新代码

(1)cd C:\Users\{{username}}\Desktop\{{filename}}

说明:若项目文件夹路径为C:\Users\{{username}}\Desktop\{{filename}},则{{username}}为操作系统的用户名,{{filename}}是你要提交代码的项目文件夹;路径也可以是其他的

(2)git add

说明:这条命令有两种用法:git add . (注意add.之间有空格)用于把当前文件夹中的所有文件都加入到上传的列表中;git add "你要添加的文件(test.txt)"

(3)git commit -m "说明"

说明:这个"说明"可以自己随意写

(4)git push -u origin master

说明:origin这个别名就是你首次向github提交代码时用的别名
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: