Idea首次提交項目到新建的git倉庫

github新建倉庫:

Alt+F12進入命令行模式

默認在項目根目錄

初始化Git代碼庫

git init 

 

添加git倉庫地址

git remote add origin XXXXXXX.git

 

獲取所有分支

git fetch

 

查看所有分支

git branch -a

如果無分支,git checkout origin/master後提示:(創建倉庫沒有添加文件的後果:Initialize this repository with a README)

error: pathspec 'origin/master' did not match any file(s) known to git.

 

Git上添加一個新文件後,git fetch獲取分支,git branch -a可看到:remotes/origin/master

 

切換到遠程master分支:

git checkout origin/master

提示如下:

 

Note: checking out 'origin/master'.

 

You are in 'detached HEAD' state. You can look around, make experimental

changes and commit them, and you can discard any commits you make in this

state without impacting any branches by performing another checkout.

 

If you want to create a new branch to retain commits you create, you may

do so (now or later) by using -b with the checkout command again. Example:

 

  git checkout -b new_branch_name

 

HEAD is now at 4beea49... Merge branch 'develop' into 'master'

 

執行git branch,效果如下:

* (HEAD detached at origin/master)

 

創建並切換本地分支

git checkout -b master

 

建立本地分支和遠程分支的追蹤關係:

git branch -u origin/master master

 

然後就可以通過idea拉取、提交項目

 

 

如果沒有commit and push

 

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