idea 中创建本地和远程仓库并推送(省去创建远程仓库和关联的步骤)


背景

原来一直写公司的项目,没有频繁创建仓库,直接clone,最近练习比较多,每次都是 新建远程仓库->本地init->git remote add -> git add -> git commit -> git push ,有时候网速还慢,心态爆炸,头皮发麻。

通过下面的方式,可以直接在idea中创建远程仓库,并推送上去。

设置git和github

git:

会自己配置好,没有设置好就自己设置下
image-20200419223118470

github:

  1. 用户名密码 用户名不是邮箱,是https://github.com/xxx 中的xxx
  2. token方式 点击Create API Token,输入在github中注册的用户名和密码生成token

image-20200419222414700

git init

image-20200419222538193

选中当前项目

项目中文件变成红色,因为

git add

image-20200419231954028

项目中文件变成绿色,此时文件只是处于暂存区,并没有真正进入到版本库中

gitcommit

image-20200419232023602

项目中文件变成黑色,此时项目文件从暂存区真正进入版本库中

image-20200419231534594

这里一定是点击commit

share project on github(必须在git add、 git commit 之后)

image-20200419222659455

image-20200419222737792

如果

image-20200419230715457

需要重新设置github

中间会弹窗输入GitHub的用户名和密码,半天不行,看最电脑下方图标有登录图标(可能被挡住了)

image-20200419230215699

image-20200419230610470

问题

image-20200419230816657

只能在github新建一个仓库,但是不能push代码上去,不能create git repository 之后直接share project on github,需要先add 、commit 再share

如果create git repository 之后直接share project on github 会提示,commit,界面是这样的

image-20200419222844843

如果已经这样了,再add commit 不行了,会提示如下,push也会提示如下

image-20200419231227592

只能删除远程仓库、删除.git文件 重新来

按照create git repository ->github git add ->commit->share project on的顺序一般是不会有问题的。

git remote

如果不想通过share,可以通过这种方式与新建好的远程仓库建立连接,还是有点繁琐

image-20200419223425657

image-20200419223446587

总结:

顺序:git init -> git add -> git commit -> share

参考

https://blog.csdn.net/qq686867/article/details/80003094
https://www.cnblogs.com/summer-fate/p/7262994.html

发布了563 篇原创文章 · 获赞 4345 · 访问量 293万+

猜你喜欢

转载自blog.csdn.net/dataiyangu/article/details/105625135