进入D 盘:
cd d:
进入CKX文件:
cd CKX
在 CKX文件中创建myBook文件夹:
mkdir myBook
进入myBook文件夹:
cd myBook
初始化仓库:
git init
查看myBook文件中已经存在的文件:
ls -a
git init
ls -a
echo "# happychen" >> readme.md
git add README.md
提交文件到本地缓存,并添加说明:
git commit -m "first commit"
这个时候提示需要做验证操作:
此时全局设置验证信息:
将本地仓库与远程仓库[email protected]:happychen666/gitTest.git 联系起来:
git remote add origin [email protected]:happychen666/gitTest.git
将本地仓库缓存的文件提交到远程仓库中:
git push -u origin master
使用git进行push或者clone操作的时候如果出现如下错误:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
原因:电脑公钥(publickey)未添加至github,所以无法识别。 因而需要获取本地电脑公钥,然后登录github账号,添加公钥至github就OK了。
设置Git的user name和email
git config --global user.name “yourname”
git config --global user.email “youremail”
生成SSH密钥:
查看是否已经有了ssh密钥:cd ~/.ssh
如果没有密钥则不会有此文件夹,有则备份删除
生成密钥:
ssh-keygen -t rsa -C “youremail”
按3个回车,则密码为空。
最后得到了两个文件:id_rsa 和 id_rsa.pub
在github上添加ssh密钥,这要添加的是id_rsa.pub里面的公钥。打开github在设置中添加密钥
登录github后,进入个人设置settings—>ssh and gpg keys–>new ssh key 添加即可。title自行命名
添加之后:
此时再重新将本地仓库缓存的文件提交到远程仓库就可以了:
首先查看现有的所有分支情况,当前所处分支前面会有个*:
git branch -a
此时远程分支上还没有test01分支。
现在创建本地test01分支并切换到这个分支:
git checkout -b test01
git checkout -b <分支名> 创建并切换到新建的分支,相当于两条命令:
git branch <分支名> 创建分支 git
checkout <分支名> 切换分支
再次查看现有的所有分支情况:
git branch -a
发现多了一个test01分支,并且当前正处于test01分支:
把本地test01分支推送到远程:
git push --set-upstream origin test01
比如这里删除远程test01分支:
git push origin --delete test01