git 推送基本操作

来源:互联网 发布:投弹兵升级数据 编辑:程序博客网 时间:2024/05/17 03:01

本文介绍使用命令行创建远程仓库,编写本地文件,添加 .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-reposmkdir 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.githttps://github.com/degawong/my-repos.git

我的一个使用命令行窗口建立的远程 repos 的项目链接为 :

https://github.com/degawong/curl-repos






0 0
原创粉丝点击