Git配合github使用

简介: 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
目录
相关文章
|
5天前
|
Linux 开发工具 git
蓝易云 - git及GitHub的使用
以上就是Git和GitHub的基本使用方法。
6 0
|
13天前
|
人工智能 Linux 开发工具
[oeasy]python018_ 如何下载github仓库_git_clone_下载仓库
在这个文档中,作者讨论了如何继续进行编程学习,特别是关于GitHub的使用。首先,回顾了从编写简单代码到管理大量代码的过程。然后,提到了通过“保存运行一条龙”操作来处理代码,以及GitHub作为全球最大的开源软件平台的重要性。在GitHub上,用户可以找到各种软件项目,包括Linux、Python和Blender等。 作者解释了GitHub的基本操作,如点赞(star)、 fork(复制项目)和watch(关注项目更新)。还介绍了如何下载项目到本地,通过`git clone`命令复制仓库的URL并将其粘贴到终端进行下载。如果遇到问题,可以尝试更换HTTP链接或等待一段时间重试。
191 1
|
21天前
|
开发工具 git
Git项目如何配置,如何上传至GitHub。其详细步骤
Git项目如何配置,如何上传至GitHub。其详细步骤
17 0
|
21天前
|
网络安全 数据安全/隐私保护
解决git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Pleas
解决git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Pleas
|
21天前
|
存储 开发工具 git
|
21天前
|
开发工具 数据安全/隐私保护 C++
vs2019中同步到github上的用户名错误_控制面板和vs的git全局设置重新登录
vs2019中同步到github上的用户名错误_控制面板和vs的git全局设置重新登录
18 0
|
21天前
|
前端开发 JavaScript 网络安全
Git(3) 使用Github管理项目
Git(3) 使用Github管理项目
29 0
|
21天前
|
开发工具 git
git如何创建新分支,GitHub默认分支是main怎么连上
git如何创建新分支,GitHub默认分支是main怎么连上
31 0
|
21天前
|
开发工具 git
对于github不同的分支main或者master,git拉取代码的时候怎么拉取不同分支的代码
对于github不同的分支main或者master,git拉取代码的时候怎么拉取不同分支的代码
31 1
|
21天前
|
Shell 开发工具 git
【Github】git bash将本地工程上传至github
【Github】git bash将本地工程上传至github