Git配合github使用

Git配合github使用

链接本地与github

  • 创建一个repository
  • 生成SSH Key
    (留空,以后再写)

git链接github

# 删除链接库
git remote rm origin    
# 添加链接库
# 首先在指定文件夹中,初始化
git init
# 接着 添加链接
git remote add origin git@github.com:XXXX.git
# 查看当前链接库
git remote -v

配置git的代理

# 查看当前代理设置
git config -l

# 添加http和https代理
git config --global https.proxy http://127.0.0.1:8080
git config --global https.proxy https://127.0.0.1:8080

# 取消代理 取消之后下载别人的代码只能通过git的方式
git config --global --unset http.proxy
git config --global --unset https.proxy

上传项目到github

git add . (注:别忘记后面的.,把当前文件夹的内容都添加进来)

git commit  -m  "提交信息" 

git push -u origin master 

两台电脑协同使用git链接github

需要先使用下述命令删除链接库

# 删除链接库
git remote rm origin    

然后再使用:

# 添加链接库
git remote add origin git@github.com:XXXX.git
# 查看当前链接库
git remote -v

接着就可以正常进行pull和push操作了。

git push -u origin master 出现错误

Updates were rejected because the remote contains work that you do not have locally. This is usually caused by another repository pushing to the same ref. You may want to first integrate the remote changes (e.g., ‘git pull …’) before pushing again. See the ‘Note about fast-forwards’ in ‘git push --help’ for details

提示说:
更新被拒绝,因为远程包含您在本地没有的工作。这通常是由另一个存储库推送到同一个引用引起的。在再次推送之前,您可能希望首先集成远程更改(例如,“git pull…”)。有关详细信息,请参阅“git push–help”中的“关于快进的说明”

因此,需要进行一个这样的操作:

# 允许不相关历史提交,并强制合并
git pull origin master --allow-unrelated-histories

猜你喜欢

转载自blog.csdn.net/wxc_1998/article/details/120543580