您的位置:首页 > 其它

git 推送基本操作

2017-04-11 19:45 274 查看
本文介绍使用命令行创建远程仓库,编写本地文件,添加 .gitignore 文件,并提交到远程仓库:

# 使用命令行创建 git 的远程仓库

curl -u 'degawong' https://api.github.com/user/repos -d '{"name":"my-repos"}'
在大括号内的 { 参数:数值 } 对中参数有很多,都可以手动设置:

# 官网给出的参数解释如下所示 :

{
"name": "degawong",
"description": "This is your first repository",
"homepage": "https://github.com",
"private": false,
"has_issues": true,
"has_projects": true,
"has_wiki": true
}

# 一般使用时,可以只使用上述几个参数,还有其他的无关紧要的参数可以选择默认
# 官网给的例子中, "private" 属性选择了私有,这个是需要缴费的,所以这个参数
# 需要修改为 false
此时,在 github 上就生成了名字为 my-repos 得远程仓库:
# 新建目录 my-repos
mkdir my-repos
# 进入到 my-repos 目录
cd my-repos
# 初始化 git 仓库
git init
# 添加远程仓库连接
git remote add origin https://github.com/degawong/my-repos.git # 编写一个项目(opencv)
……
# 添加 .gitignore 文件
touch .gitignore
# 编写 .gitignore 文件 去除自动生成得文件夹与中间文件等
vi .gitignore
# 添加本目录下的所有文件
git add .
# 提交添加的所有文件
git commit -m"it's a curl repos solution"
# 提交到远程仓库(首次提交添加 -u)
git push -u origin master

仓库名字可能忘记或者写错,或者只是想改变一个连接的远程仓库,此时可以使用“
# 断开当前的远程 repos 连接
git remote rm <name of repos>
git add origin master <name of repos>
# 还有这种方式也可以
git remote set-url origin url

还有,要注意的是,建立的 git repos 名称有两种命名方式:
# 分别为 ssh 与 https 方式,根据个人爱好使用
git@github.com/degawong/my-repos.git https://github.com/degawong/my-repos.git 我的一个使用命令行窗口建立的远程 repos 的项目链接为 :

https://github.com/degawong/curl-repos
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: