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