git 推送基本操作

本文介绍使用命令行创建远程仓库,编写本地文件,添加 .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






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值