把文件上傳到git,但本地還沒有這個項目,怎麼辦?需要新建Git倉庫並添加本地項目

需要新建Git倉庫並添加本地項目

1 新建目錄git_dir,把需要上傳到git的文件enc.jar複製到這個目錄下

2 初始化當前目錄作爲Git倉庫:

git init

3 添加目錄下的文件到本地倉庫:從工作區提交到暫存區

git add enc.jar  

# git add . 添加當前目錄下的所有文件

4 提交staged的文件,從暫存區提交到本地代碼倉庫

git commit -m "提交enc.jar"

5 使用命令行添加遠程倉庫的地址。

git remote add origin https://github.com/...../abc.git

6 git pull

  此時可能會報錯,提示輸入username,password

 輸入後,再git pull,可能仍然會報錯:

gitThere is no tracking information for the current branch.

Please specify which branch you want to merge with.

See git-pull(1) for details

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> merged0.9.6

是因爲本地分支和遠程分支沒有建立聯繫  (使用git branch -vv  可以查看本地分支和遠程分支的關聯關係)  .根據命令行提示只需要執行以下命令即可

git branch --set-upstream-to=origin/master master  ,把遠程master分支,關聯到本地master分支

# git branch --set-upstream-to=origin/遠程分支的名字 本地分支的名字 

再次運行git pull會發現git_dir目錄下有很多從遠程master分支上下載下來的文件

7 提交文件

 git push origin master ,從本地代碼庫提交到遠程代碼庫的master分支

 

使用 git branch -a 能看到本地和遠程的所有分支。

參考:

https://blog.csdn.net/theonegis/article/details/80115316

https://blog.csdn.net/ming13849012515/article/details/81011632

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