Git常见的错误以及处理
1.添加远程仓库
$ git remote add origin (github帐号名)/gitdemo(项目名).git
解决办法如下:
1、先输入
git remote add origin git@github.com:djqiang/gitdemo.git 就不会报错了!
3、如果输入$ git remote rm origin 还是报错的话,error: Could not remove config section 'remote.origin'. 我们需要修改gitconfig文件的内容
4、找到你的github的安装路径,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc
5、找到一个名为gitconfig的文件,打开它把里面的[remote "origin"]那一行删掉就好了!
2.提交代码时提示错误
requested URL returned error: 403
//如果出现403 表示没有权限提交代码
2.1.解决办法如下:
在.git配置文件下加上username:password@就好了 (SmartTuwei@github.com/SmartTuwei/…)
2.2.也可以清除掉git客户端中的缓存信息
$ git credential-manager uninstall
$ git credential-manager install
3.如果输入$ ssh -T git@github.com, 提示错误
Permission denied (publickey).
//因为新生成的key不能加入ssh就会导致连接不上github。
解决办法如下:
1、先输入
$ ssh-agent,再输入$ ssh-add ~/.ssh/id_key ,
这样就可以了。
2、如果还是不行的话,输入ssh-add ~/.ssh/id_key 命令后出现报错Could not open a connection to your authentication agent.解决方法是key用Git Gui的ssh工具生成,这样生成的时候key就直接保存在ssh中了,不需要再ssh-add命令加入了,其它的user,token等配置都用命令行来做。
3、最好检查一下在你复制id_rsa.pub文件的内容时有没有产生多余的空格或空行,有些编辑器会帮你添加这些的。
4.如果输入$ git push origin master,提示出错信息:
error:failed to push som refs to .......
解决办法如下:
1、先输入$ git pull origin master //先把远程服务器github上面的文件拉下来
2、再输入$ git push origin master
如果继续报错:
fatal: Couldn't find remote ref master或者
fatal: 'origin' does not appear to be a git repository以及
fatal: Could not read from remote repository.
则需要重新输入
$ git remote addorigingit@github.com:djqiang/gitdemo.git
5.输入$ git push -u origin master To git@github.com:******/Demo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:******/Demo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
是因为远程repository和我本地的repository冲突导致的,而我在创建版本库后,在github的版本库页面点击了创建README.md文件的按钮创建了说明文档,但是却没有pull到本地。这样就产生了版本冲突的问题。
有如下几种解决方法:
1.使用强制push的方法:
$ git push -u origin master -f
这样会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候。
2.push前先将远程repository修改pull下来
$ git pull origin master
$ git push -u origin master
3.若不想merge远程和本地修改,可以先创建新的分支:
$ git branch [name] 然后push $ git push -u origin [name];
6.gitconfig配置文件
Git有一个工具被称为gitconfig,它允许你获得和设置配置变量;这些变量可以控制Git的外观和操作的各个方面。这些变量可以被存储在三个不同的位置:
1./etc/gitconfig 文件:包含了适用于系统所有用户和所有库的值。如果你传递参数选项’--system’ 给 git config,它将明确的读和写这个文件。
2.~/.gitconfig 文件 :具体到你的用户。你可以通过传递--global 选项使Git 读或写这个特定的文件。
3.位于git目录的config文件 (也就是 .git/config) :无论你当前在用的库是什么,特定指向该单一的库。每个级别重写前一个值。因此,在.git/config中的值覆盖了在/etc/gitconfig中的同一个
7.配置相关信息:
7.1.当你安装Git后首先要做的事情是设置你的用户名称和e-mail地址。这是非常重要的,因为每次Git提交都会使用该信息。它被永远的嵌入到了你的提交中:
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
7.2.你的编辑器(Your Editor)
现在,你的标识已经设置,你可以配置你的缺省文本编辑器,Git在需要你输入一些消息时会使用该文本编辑器。缺省情况下,Git使用你的系统的缺省编辑器,这通常可能是vi 或者vim。如果你想使用一个不同的文本编辑器,例如Emacs,你可以做如下操作:
$ git config --global core.editor emacs
7.3 如果你想检查你的设置,你可以使用
git config --list 命令来列出Git可以在该处找到的所有的设置:
$ git config --list
git config user.name
8.github版本库,在push代码时出错:
8.1提交时报错( You have not concluded your merge (MERGE_HEAD exists))
处理办法:强制push : $ git push -u [远程分支] -f
centos 7 安装git 服务器报错如下:
bash: git-upload-pack: command not found fatal: The remote end hung up unexpectedly
原因:原来代码服务器上的git安装路径是/usr/local/git,不是默认路径,根据提示,在git服务器上, 建立链接文件:
解决方法:
ln -s /usr/local/git/bin/git-upload-pack /usr/bin/git-upload-pack
再次执行 git clone 成功!
报错如下: bash: git-receive-pack: command not found fatal: Could not read from remote repository.
# ln -s /usr/local/git/bin/git-receive-pack /usr/bin/git-receive-pack