一、常见操作

1. 使用git在本地创建一个项目的过程

  1. $ makdir ~/hello-world //创建一个项目hello-world
  2. $ cd ~/hello-world //打开这个项目
  3. $ git init //初始化
  4. $ touch README
  5. $ git add README //更新README文件
  6.  
  7. $ git add . //添加当前目录下的所有文件 )
  8. $ git commit -m 'first commit' //提交更新,并注释信息“first commit”
  9. $ git remote add origin git@github.com:defnngj/hello-world.git //连接远程github项目
  10. $ git push -u origin master //将本地项目更新到github项目上去
  1. $ echo "# MyActualProjects" >> README.md
  2. $ git init
  3. $ git add README.md
  4. $ git commit -m "first commit"
  5. $ git remote add origin https://github.com/shenxiaolinZERO/MyActualProjects.git
  6. $ git push -u origin master

或者是:

注册一个github账号。
登录github网站,在github网页上创建一个仓库,起个名字(比如叫做:160313T)。之后你复制得到这个仓库的url地址 。
在你电脑上用git clone [url地址]命令把github上的仓库克隆到本地。
之后你电脑上会多出来一个 160313T 文件夹。把你将要git到github上的文件复制到这个文件夹里面。
之后用git add、git submit之类的命令把文件弄到git仓库去。
因为还没使用git push命令,因此github上的仓库和你电脑上的仓库并不一致。你要用git push把本地仓库“上传”到github上去。

  1. $ git clone https://github.com/shenxiaolinZERO/160313.git
  2.  
  3. $ git init // 初始化
  4.  
  5. $ git add .
  6.  
  7. $ git commit -m "yesyoucan"
  8.  
  9. $ git remote add origin https://github.com/shenxiaolinZERO/160313.git
  10.  
  11. $ git push -u origin master

示例如下:

2.gitconfig配置文件

Git有一个工具被称为git config,它允许你获得和设置配置变量;这些变量可以控制Git的外观和操作的各个方面。这些变量可以被存储在三个不同的位置: 
         1./etc/gitconfig 文件:包含了适用于系统所有用户和所有库的值。如果你传递参数选项’--system’ 给 git config,它将明确的读和写这个文件。 
         2.~/.gitconfig 文件 :具体到你的用户。你可以通过传递--global 选项使Git 读或写这个特定的文件。
         3.位于git目录的config文件 (也就是 .git/config) :无论你当前在用的库是什么,特定指向该单一的库。每个级别重写前一个级别的值。因此,在.git/config中的值覆盖了在/etc/gitconfig中的同一个值。
        在Windows系统中,Git在$HOME目录中查找.gitconfig文件(对大多数人来说,位于C:\Documents
and Settings\$USER下)。它也会查找/etc/gitconfig,尽管它是相对于Msys
根目录的。这可能是你在Windows中运行安装程序时决定安装Git的任何地方。

配置相关信息:

2.1 当你安装Git后首先要做的事情是设置你的用户名称和e-mail地址。这是非常重要的,因为每次Git提交都会使用该信息。它被永远的嵌入到了你的提交中:

  1. $ git config --global user.name "shenxiaolin"
  2. $ git config --global user.email shenxiaolin@example.com

2.2    你的编辑器(Your Editor)

  现在,你的标识已经设置,你可以配置你的缺省文本编辑器,Git在需要你输入一些消息时会使用该文本编辑器。缺省情况下,Git使用你的系统的缺省编辑器,这通常可能是vi 或者 vim。如果你想使用一个不同的文本编辑器,例如Emacs,你可以做如下操作:

  1. $ git config --global core.editor emacs

2.3 检查你的设置(Checking Your Settings)

  如果你想检查你的设置,你可以使用 git config --list 命令来列出Git可以在该处找到的所有的设置:

  1. $ git config --list

你也可以查看Git认为的一个特定的关键字目前的值,使用如下命令 git config {key}:

  1. $ git config user.name

2.4 获取帮助(Getting help)

  如果当你在使用Git时需要帮助,有三种方法可以获得任何git命令的手册页(manpage)帮助信息:

  1. $ git help <verb>
  2. $ git <verb> --help
  3. $ man git-<verb>

  例如,你可以运行如下命令获取对config命令的手册页帮助:

  1. $ git help config

二、常见错误及其解决办法

Q1:如果输入$ git remote add origin git@github.com:djqiang(github帐号名)/gitdemo(项目名).git

提示出错信息:fatal: remote origin already exists.

解决办法如下:

1、先输入$ git remote rm origin

2、再输入$ 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"]那一行删掉就好了!

Q2: 如果输入$ 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文件的内容时有没有产生多余的空格或空行,有些编辑器会帮你添加这些的。

Q3: 如果输入$ git push origin master

提示出错信息:error:failed to push som refs to .......

解决办法如下:

1、先输入$ git pull origin master //先把远程服务器github上面的文件拉下来

2、再输入$ git push origin master

3、如果出现报错 fatal: Couldn't find remote ref master或者fatal:
'origin' does not appear to be a git repository以及fatal:
Could not read from remote repository.

4、则需要重新输入$ git remote add origingit@github.com:djqiang/gitdemo.git

 Q4 : 非首次提交到某仓库时,当git add . 或者 git commit -m "messages"

出现以下错误:

  1. $ git add .
  2. fatal: Unable to create '//Mac/Home/Desktop/TGh/02/.git/index.lock': File exists.
  3.  
  4. If no other git process is currently running, this probably means a
  5. git process crashed in this repository earlier. Make sure no other git
  6. process is running and remove the file manually to continue.

解决办法如下:

输入: git rm -f ./.git/index/lock   就可以解决问题了。

Q5:fatal: the remote end hung up unexpectedly

  解决办法:

  发生在push命令中,有可能是push的文件过大导致
  解决方法:

  windows:  在 .git/config 文件中加入  [http] postBuffer = 524288000

     
linux:  git config http.postBuffer 524288000

  Q6:在使用git 对源代码进行push到gitHub时可能会出错,信息如下:

failed to push some refs to 'git@github.com:shenxiaolinZERO/CRIMSystem.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.

出现错误的主要原因是github中的README.md文件不在本地代码目录中.

解决方法:

  可以通过如下命令进行代码合并【注:pull=fetch+merge]

  git pull --rebase origin master

  执行上面代码后可以看到本地代码库中多了README.md文件。

此时再执行语句 git push -u origin master即可完成代码上传到github:

Q7 :(20180204)

原先是在电脑A完成的clone并初始化本地仓库的项目P1并完成提交到GitHub的操作。

现在要在电脑B上更新P1并完成提交到GitHub。提交时出现以下这个问题:

  1. error: failed to push some refs to 'https://github.com/shenxiaolinZERO/PracticeOfPython.git'
  2. hint: Updates were rejected because the remote contains work that you do
  3. hint: not have locally. This is usually caused by another repository pushing
  4. hint: to the same ref. You may want to first integrate the remote changes
  5. hint: (e.g., 'git pull ...') before pushing again.
  6. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

解决办法:

push的命令加一个-f :即  $ git push -f origin master

注:参考于:http://stackoverflow.com/questions/7860751/git-fatal-unable-to-create-path-my-project-git-index-lock-file-exists

http://www.question-defense.com/2009/02/16/permission-denied-publickey-fatal-the-remote-end-hung-up-unexpectedly

http://blog.csdn.net/dengjianqiang2011/article/details/9260435

github常见操作和常见错误及其解决办法的更多相关文章

  1. 常见反编译产生错误 k__BackingField 解决办法

    常见反编译产生错误 k__BackingField 解决办法     无聊反编译小蚂蚁出现上千的错同样的错       private bool <EnableRuntimeHandler> ...

  2. WebStorm中将Project分享到GitHub时报“Error Running Git”错误的解决办法

    错误信息 Cannot run program "git.exe":CreateProcess error=2,系统找不到指定的文件. 解决办法 从错误信息就可以知道,WebSto ...

  3. Docker Hadoop 配置常见错误及解决办法

    Docker Hadoop 配置常见错误及解决办法 问题1:wordcount运行卡住,hadoop 任务运行到running job就卡住了 INFO mapreduce.Job: Running ...

  4. MVC MVC常见错误及解决办法

    MVC常见错误及解决办法 问题1: 必须添加对程序集“EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c5 ...

  5. Ubuntu下Linux配置内核各种常见错误和解决办法

    镜像下载.域名解析.时间同步请点击阿里云开源镜像站 这篇把Ubuntu下Linux配置内核各种常见错误和解决办法给大家讲解一下,希望可以帮助到大家. 一.Ubuntu系统中缺少各种依赖包导致的问题 1 ...

  6. Oracle的常见错误及解决办法

    ORA-12528: TNS:listener: all appropriate instances are blocking new connections ORA-12528问题是因为监听中的服务 ...

  7. 使用wubi安装ubuntu14.04出现的常见错误的解决办法

    花了一天的时间终于安装上了Ubuntu14.04,过程坎坷,是血泪史,开始报“cannot download the metalink and therefore the ISO”错误,解决后,又报“ ...

  8. Android开发 |常见的内存泄漏问题及解决办法

    在Android开发中,内存泄漏是比较常见的问题,有过一些Android编程经历的童鞋应该都遇到过,但为什么会出现内存泄漏呢?内存泄漏又有什么影响呢? 在Android程序开发中,当一个对象已经不需要 ...

  9. 5个Android开发中比较常见的内存泄漏问题及解决办法

    android中一个对象已经不需要了,但是其他对象还持有他的引用,导致他不能回收,导致这个对象暂存在内存中,这样内存泄漏就出现了.   内存泄漏出现多了,会是应用占用过多的没存,当占用的内存超过了系统 ...

随机推荐

  1. cas4.0 session中返回更多的用户信息

    实现思路: 新增AccoutAttributeDao类继承StubPersonAttributeDao,重写getPerson方法.实际应用中我们只需要修改getPersion方法中的内容,根据实际情 ...

  2. 【HDOJ】【1964】Pipes

    插头DP 做完Formula 1以后这就是傻逼题了……直接将“数路径方案数”改为“计算路径长度取最小值”即可,没多大难度 都不用判当前格子是否能够到达的……不过!外边的一圈“墙”还是要加的!不然会有冗 ...

  3. VC++ 改动VMware BIOS、uuid_location、ethernet0_address等

    VC++ 改动VMware BIOS.uuid_location.ethernet0_address等.主要问题例如以下 (1)随机产生16进制数. (2)改动vmx相应项.依据规则一般仅仅改动最后三 ...

  4. 3D有向包围盒与球体碰撞的算法

    之前发的小游戏滚蛋躲方块中,用它来判断球体与立方体是否发生了碰撞. http://www.cnblogs.com/WhyEngine/p/3350012.html 现在发布下该算法: 有向包围盒OBB ...

  5. water-and-jug-problem

    以下这个解法也是参考了一些讨论: https://leetcode.com/discuss/110235/c-solution-using-euclidean-algorithm 还有这个解释原理的, ...

  6. Windows Server上用于iSCSI的网卡的必备设置

    如下的修改是iSCSI网卡的推荐配置, 新装起来的Host不要忘记改起来哦. 其原理是强制走iSCSI通讯的网卡立即对到来的TCP报文(segment)做出acknowledge, 从而解决iSCSI ...

  7. Foreda8上安装CMake2.8.1.2

    本机操作系统:Linux 2.6.23.1-42.fc8 #1 SMP Tue Oct 30 13:55:12 EDT 2007 i686 i686 i386 GNU/Linux 在本机上准备安装My ...

  8. 【线段树】HDU 3397 Sequence operation 区间合并

    操作 Change operations: 0 a b change all characters into '0's in [a , b] 1 a b change all characters i ...

  9. Android 之 AndroidManifest.xml 详解(一)

    当Android启动一个应用程序组件之前,它必须知道哪些个组件是存在的,所以开发人员在开发过程中,必须将应用程序中出现的组件一一在AndroidManifest.xml文件中" 声明 &qu ...

  10. sse float 转int 截断和不截断

    之前, 我用sse指令, 想把float 型转成int, 不过其中遇到了一些困惑,就是截断和不截断的问题, 这个问题一直困扰我好集体, 最后终于解决了, 原来sse本身就有截断和不截断的指令. _mm ...