git代码管理入门
*2022/05/12
GitHub中文手册
目录
- 仓库
- 基础的push
- git remote
- 一些基础指令
- 在GitHub仓库里关联图片
- git clone连接超时
- git: Failed to connect to localhost port 1080: Connection refused
- warning: adding embedded git repository
- git remote不显示地址
仓库
在自己的仓库里,可以创建新分支。在别人的仓库里,可以Fork某条分支到自己的仓库。
git init
或git clone <url>
均可创建仓库。
基础的push
git add .
git commit -m <desc>
git push
git remote
git remote [-v]
查看远程仓库[详情]。git remote add <name> <url>
添加远程仓库地址。
一些基础指令
git status
查看仓库状态,如是否有未提交文件等。git clean -f
删掉未同步的文件。删后找不到
上传图片至GitHub仓库,并在markdown里显示
有时需要在readme等显示图片,通过如下url格式关联仓库里的图片:
https://github.com/<username>/<repo>/raw/<branch>/<img_dir>/.png or.jpg
# 这是我的仓库图片地址
https://github.com/Fuger2021/Hello-World/raw/master/img/p1.jpg
git clone连接超时
git clone能不能连得上是个比较看运气的事。
# 换镜像源
git clone https://hub.fastgit.org/<address>
正面解决问题,最好设置一下代理。设置git SSH代理
用SSH会比http快一点。
git: Failed to connect to localhost port 1080: Connection refused
有时git clone连接不上还可能是因为代理出现问题。个人平时多用规则连接,连不上则换全局。这里记录一下网上的说法,我试了但是感觉好像没什么用。
warning: adding embedded git repository
试图添加嵌套的git仓库。我在git add时报了这个问题,原因是在已经git init的文件夹里执行了git clone。
解决方法:直接删光就行了,找个空白文件夹重新clone。进入clone后的项目里,执行git add。
git remote不显示地址
如果你正常clone下来,是会自动创建两条远程仓库地址的
$ git remote -v
> origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
> origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
注意是在仓库里操作的,即你现在所处的位置应该和.git
同级。实在没有的话手动创建一下
git remote add origin https://github.com/<address>
再次查询应该就能查到了。这些配置都保存在gitconfig文件里,可以去手动修改一下。
参考博客