a186r avatar

git相关配置

a186r

Published: 03 Apr 2018 › Updated: 03 Apr 2018

git相关配置

在ubuntu上又重新把git配置了一遍,整理一下

1.安装
sudo apt install git

2.本地生成ssh key:
ssh-keygen -t rsa -C "myname@email.com"

3.在github中添加SSH key

4.测试ssh key是否成功
ssh -T git@github.com

  • 若出现You’ve successfully authenticated, but GitHub does not provide shell access。表示已经成功连接github(warning忽略)。
  • 若出现Agent admitted failure to sign using the key.Permission denied (publickey)。使用命令 ssh -add

5.配置git配置文件,username和email,这个都是本地的,每次commit的时候git都会记录
git config --global user.name "your name"
git config --global user.email "your email"

6.在github上创建一个仓库

7.上传本地仓库到git
cd到文件目录
git init初始化本地仓库
然后连接到远程仓库git remote add origin git@github.com:yourName/yourRepo.git
在本地库中,.git/config,会有一个remote “origin”内容,可以直接修改来配置远程地址。

然后工作流操作(工作目录--暂存区--HEAD):

  • git add <filename>或者git add *,自动判断添加哪些文件,添加至暂存区,可以多次使用
  • git commit -m "代码提交信息(更新日志等)"提交文件至HEAD
  • git push origin master提交文件至远程仓库
    这里如果产生冲突,看提示,一般需要pull一次然后再push就正常了

8.clone远程仓库及wiki
git clone git@github.com:myname/respository.git
git clone git@github.com:myname/respository.wiki.git

9.添加其他远程仓库
git remote add <shortname> <url>
shortname指定一个轻松使用的简写
url可在git的仓库右边复制 HTTPS clone url

10.创建一个分支
git checkout -b feature-x

11.切换分支
git checkout master

12.删除分支
git branch -d feature-x

13.将分支push至远程仓库
git push origin <branch>

其他命令在--help中查看吧

Leave git相关配置 to:

Written by

Read more #git posts


Best Posts From a186r

We have not curated any of a186r's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From a186r