GitHub 日常使用

(1)复制项目到本地

git clone git://github.com:xxxx/test.git ##以gitreadonly方式克隆到本地,只可以读  
git clone [email protected]:xxx/test.git  ##以SSH方式克隆到本地,可以读写  
git clone https://github.com/xxx/test.git ##以https方式克隆到本地,可以读写  
git fetch [email protected]:xxx/xxx.git  ##获取到本地但不合并  
git pull [email protected]:xxx/xxx.git ##获取并合并内容到本地

(2)新建Git项目并提交到Github

mkdir testdir & cd testdir  
touch README.md  
git init #初始化一个本地库  
git add README.md #添加文件到本地仓库  
git rm README.md #本地倒库内删除  
git commit -m "first commit" #提交到本地库并备注,此时变更仍在本地。  
git commit -a  ##自动更新变化的文件,a可以理解为auto  
git remote add xxx [email protected]:xxx/xxx.git  #增加一个远程服务器的别名。  
git remote rm xxx   ##删除远程版本库的别名  
git push -u remotename master #将本地文件提交到Github的remoname版本库中。此时才更新了本地变更到github服务上。

(3)Github添加密钥

设置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 "[email protected]"  #按3个回车,密码为空。

Your identification has been saved in 
C:\Users\knight.DESKTOP-G27F5NG\.ssh.ssh、id_rsa. Your public key has been saved in C:\Users\knight.DESKTOP-G27F5NG\.ssh\id_rsa.pub. The key fingerprint is: ……………… 

#最后得到了两个文件:id_rsa和id_rsa.pub

打开 https://github.com/,在设置中添加密钥

猜你喜欢

转载自blog.csdn.net/knight_zhou/article/details/106782994