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 方式,根據個人愛好使用
[email protected]/degawong/my-repos.git
https://github.com/degawong/my-repos.git

我的一個使用命令行窗口建立的遠程 repos 的項目鏈接爲 :

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






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章