美文网首页
git与远程仓库关联,并提交代码

git与远程仓库关联,并提交代码

作者: Able7 | 来源:发表于2019-02-15 20:21 被阅读0次

在git项目的根目录下,创建.gitignore
echo *.pyc >.gitignore //排除所有以.pyc为后缀的文件
比如python项目下,想排除venv 、 _pycache_ 2个目录,可以写成如下:

#cat .gitignore 
venv/
__pycache__/
.*                 #忽略以.开头的文件或目录
*.a                #忽略所以以.a为扩展名的文件
doc/*.txt          #忽略文件比如doc/1.txt,但是文件如doc/server/a.txt 不忽略

目录排除一定需要在目录名后面加反斜杠 / ,不然会当成单文件处理。

# git add .
# git commit -m"添加gitignore忽略文件"

若要排除.gitignore文件本身,需要修改.git/info/exclude 文件,添加如下:

.gitignore

Case 1 :

将本地代码与远程仓库关联,并提交代码

origin  https://github.com/xxx/ws_tornado (fetch)
origin  https://github.com/xxx/ws_tornado (push)
  • 添加本地代码
    #git add . //添加需要提交的代码
    #git commit -m 'add all' //提交代码到本地仓库

  • 提交代码到远程仓库
    # git push

fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

出现以上报错,说是当前分支master没有上游分支,为了推送当前分支并与远程分支建立关联,需要执行:
# git push --set-upstream origin master

指向完之后,由出现如下报错:

To https://github.com/xxx/ws_tornado
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/xxx/ws_tornado'
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.

# git branch --set-upstream-to=origin/master master
# git pull
【若这一步报错“fatal: refusing to merge unrelated histories”,
则执行git pull origin master --allow-unrelated-histories】
建立与远程分支的关联,并将远程仓库代码拉到本地

  • 最后提交代码至远程仓库:
    # git push

相关文章

  • Git 入门到放弃

    简介 git关联远程仓库 本地仓库与远程仓库同步问题 Git 终端命令 git关联远程仓库 基本流程 注册gith...

  • git 重新关联远程分支

    重新跟踪远程文件 使用场景:本地有原代码,但是没有与远程Git仓库做关联,或关联不正确,需要重新跟踪远程git仓库...

  • git与远程仓库关联,并提交代码

    在git项目的根目录下,创建.gitignoreecho *.pyc >.gitignore //排除所有以...

  • git 笔记

    git 本地库创建: cd 到目标文件 本地库初始化 关联远程仓库到本地 git代码提交: 添加并提交暂存区的修改...

  • git 仓库

    git 初始化 初始化git init git 新建 git 仓库,关联远程仓库 关联远程仓库git remote...

  • git本地仓库关联远程仓库的两种方式

    git本地仓库关联远程仓库的两种方式: 1.将远程的代码clone到本地仓库 2.将本地的代码关联到远程仓库 第1...

  • git

    删除关联的远程仓库 git remote remove 添加新的远程仓库关联 git remote ...

  • Git 常用命令

    远程仓库: git remote add origin 关联远程仓库 git remote remove ori...

  • Git常用命令大全

    // 初始化仓库 git init //从远程仓库克隆 git clone // 关联远程仓库 git remot...

  • 如何快速关联/修改Git远程仓库地址

    如何快速关联/修改Git远程仓库地址? 按照如下步骤即可快速实现关联/修改Git远程仓库地址:删除本地仓库当前关联...

网友评论

      本文标题:git与远程仓库关联,并提交代码

      本文链接:https://www.haomeiwen.com/subject/jeomeqtx.html