之前使用git一直都没有深入其原理,现在整理一下。
git version 查看git版本
clone和fork
https://blog.youkuaiyun.com/u010089395/article/details/21100661
配置Git
首先在本地创建ssh key;
$ ssh-keygen -t rsa -C "your_email@youremail.com"
接下来我们要做的就是把本地仓库传到github上去,在此之前还需要设置username和email
$ git config --global user.name "your name"
$ git config --global user.email "your_email@youremail.com"
进入要上传的仓库,右键git bash,添加远程地址:
$ git remote add origin git@github.com:yourName/yourRepo.git
报错 fatal: Not a git repository (or any of the parent directories): .git
解决 git init
报错 fatal: remote origin already exists
解决 git remote rm origin
git remote add origin git@github.com:yourName/yourRepo.git
检出仓库
创建一个本地仓库的克隆版本:(跳过)
git clone /path/to/repository
工作流
你的本地仓库由 git 维护的三棵"树"组成。第一个是你的 工作目录,它持有实际文件;第二个是 暂存区(Index),它像个缓存区域,临时保存你的改动;最后是 HEAD,它指向你最后一次提交的结果。
你可以提出更改(把它们添加到暂存区),使用如下命令:
git add <filename>
git add *
如果在目录里面,使用:git add .
使用如下命令以实际提交改动:
git commit -m "代码提交信息"
现在,你的改动已经提交到了 HEAD,但是还没到你的远端仓库。
推送改动
你的改动现在已经在本地仓库的 HEAD 中了。执行如下命令以将这些改动提交到远端仓库:
git push origin master 或者 git push -u origin master
报错 Unable to find remote helper for 'https'
解决 将 /usr/lib/git 纳入 PATH,至少在使用 git 之前,设置一下PATH。
$ PATH=$PATH:/usr/lib/git
报错 error: RPC failed; HTTP 403 curl 22 The requested URL returned error: 403 Proxy_UploadNotAllowed
解决 修改 config 文件
由原来的
url = https://github.com/YoungZHU/OtherLang.git
改成
url = ssh://git@github.com/YoungZHU/OtherLang.git
报错 ssh: connect to host github.com port 22: Connection timed out
没解决 重新生成key???
如果你还没有克隆现有仓库,并欲将你的仓库连接到某个远程服务器,你可以使用如下命令添加:
git remote add origin <server>
分支
创建一个叫做"feature_x"的分支,并切换过去:
git checkout -b feature_x
切换回主分支:
git checkout master
再把新建的分支删掉:
git branch -d feature_x
除非你将分支推送到远端仓库,不然该分支就是 不为他人所见的:
git push origin <branch>
更新与合并
要更新你的本地仓库至最新改动,执行:
git pull
以在你的工作目录中 获取(fetch) 并 合并(merge) 远端的改动。
要合并其他分支到你的当前分支(例如 master),执行:
git merge <branch>
http://www.runoob.com/w3cnote/git-guide.html
create a new repository on the command line
echo "# char-RNN-TensorFlow" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/cwxcode/char-RNN-TensorFlow.git
git push -u origin master
总结:
ssh-keygen -t rsa -C "your_email@youremail.com"
在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key。
回到github上,进入 Account Settings(账户配置),左边选择SSH Keys,Add SSH Key,title随便填,粘贴在你电脑上生成的key。
git config --global user.name "your name"
git config --global user.email "your_email@youremail.com"
进入要上传的仓库,右键git bash
git init
git remote add origin git@github.com:yourName/yourRepo.git
git add .
git commit -m "代码提交信息"
git push -u origin master