git学习

之前使用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
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WX Chen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值