Git使用


git

黑马[Git教程]

git基本理论

git项目搭建

搭建项目啦

具体使用流程

本地仓库搭建

创建全新的仓库

需要用 Git 管理的项目的根目录执行

git init
克隆远程仓库
git clone git@github.com:wgmzyx/DeepLearningFlappyBird.git

远程仓库搭建

使用gitee或者GitHub建立仓库

设置本机绑定 SSH 公钥,可以实现免密码登录,只需要设置一次

在push前可以检查公钥是否连接正常

ssh -T git@gitee.com
ssh -T git@github.com

本地仓库上传到远程仓库

在本地仓库根目录右键单击选择Git Bash Here

添加到缓存库

git add .

提交到本地库

# git commit -m ‘注释内容’
git commit -m "初始提交"

与远程库建立连接

git remote add origin git@github.com:wgmzyx/DeepLearningFlappyBird.git

推送到远程库

git push -u origin main

其他相关命令

设置及查看配置信息

git config --global user.name “用户名”
git config --global user.email “邮箱”
git config --global user.name
git config --global user.email

查看已经关联的仓库

git remote -v

删除关联的仓库

git remote rm origin

查看的修改的状态(暂存区、工作区)

git status
  • 新创建的文件是未跟踪状态 untracked
  • 提交后commited

查看提交日志

git log

问题

  • 因为在本地新建库后,与远程仓库的内容不一致导致的(远程仓库有一些内容本地没有)
 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'github.com:wgmzyx/DeepLearningFlappyBird.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

解决:

在push前把本地仓库的变化连接到远程仓库master

git pull origin master --allow-unrelated-histories
  • 在GitHub上克隆资源时较慢
#查看设置的属性
git config --global -l
# socks5协议,1080端口修改成自己的本地代理端口,开启此代理后push时不可
# 以免密码登录
git config --global http.https://github.com.proxy socks5://127.0.0.1:10808
git config --global https.https://github.com.proxy socks5://127.0.0.1:10808

# http协议,1081端口修改成自己的本地代理端口
git config --global http.https://github.com.proxy https://127.0.0.1:10809
git config --global https.https://github.com.proxy https://127.0.0.1:10809
#此处只对github加速,对其他不加速,使用的代理为v2ray中的代理端口

#取消限定github的代理
git config --global --unset http.https://github.com.proxy
git config --global --unset https.https://github.com.proxy

文章作者: Wgm
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Wgm !
  目录