一、gittutorial
1 建立全局信息
It is a good idea to introduce yourself to Git with your name and public email address before doing any operation. The easiest way to do so is:
git config --global user.name "Your Name Comes Here"
git config --global user.email you@yourdomain.example.com
2 具体操作
(1)初始化
git init
Git will reply
Initialized empty Git repository in .git/
You’ve now initialized the working directory—you may notice a new directory created, named “.git”.
(2)添加内容
tell Git to take a snapshot of the contents of all files under the current directory (note the .), with git add:
git add .
This snapshot is now stored in a temporary staging area which Git calls the “index”.
(3)记录变化
You can permanently store the contents of the index in the repository with git commit:
git commit
This will prompt you for a commit message. You’ve now stored the first version of your project in Git.
(4)添加内容+ 记录变化
Alternatively, instead of running git add beforehand, you can use
git commit -a
which will automatically notice any modified (but not new) files, add them to the index, and commit, all in one step.
(5)建立分支
A single Git repository can maintain multiple branches of development. To create a new branch named “experimental”, use
git branch experimental
(6)显示分支信息
git branch
you’ll get a list of all existing branches:
experimental
* master
The “experimental” branch is the one you just created, and the “master” branch is a default branch that was created for you automatically. The asterisk marks the branch you are currently on;
(7)改变分支
type
git checkout experimental
to switch to the experimental branch.
(8)合并分支改变
To merge the changes made in experimental into master, run
git merge experimental
If the changes don’t conflict, you’re done.
二、设置git pull/push 免密码
1 注意gitee支持公钥的类型
Gitee 提供了基于SSH协议的Git服务,在使用SSH协议访问仓库之前,需要先配置好账户/仓库的SSH公钥。
应该
git clone git@gitee.com:XXXXX/XXXXX.git
而不是
git clone https://gitee.com/XXXXX/XXXXX.git
如果clone的方式错了,而且项目不大删除目录重新执行:
git clone git@gitee.com:XXXXX/XXXXX.git
如果已经clone并且项目比较大那修改配置的Remote地址为SSH地址。
git remote set-url origin git@gitee.com:XXXXX/XXXXX.git
2 gitee和git的加密算法不同
gitee不支持rsa加密,支持ed25519加密,通过下面命令获得密钥。
ssh-keygen -t ed25519 -C "xxxxx@xxxxx.com"
git支持rsa加密,通过下面命令获得密钥。
ssh-keygen -t rsa -C "xxxxx@xxxxx.com"
注意:这里的 xxxxx@xxxxx.com 只是生成的 sshkey 的名称,并不约束或要求具体命名为某个邮箱。
3 配置多个SSH-Key名
添加-f参数设置生成文件
ssh-keygen -t ed25519 -C 'first@XXX.com' -f ~/.ssh/first_id_ed25519
ssh-keygen -t ed25519 -C 'second@XXX.com' -f ~/.ssh/second_id_ed25519
4 获取公钥
输入下面命令生成密钥
ssh-keygen -t ed25519 -C "xxxxx@xxxxx.com"
通过查看 ~/.ssh/id_ed25519.pub 文件内容,获取到公钥内容
cat ~/.ssh/id_ed25519.pub
复制生成后的 ssh key,通过gitee仓库主页 「管理」->「部署公钥管理」->「添加部署公钥」 ,添加生成的公钥添加到仓库中。
5 添加gitee到本机SSH可信列表
首次使用需要添加并确认gitee到本机SSH可信列表,在终端(Terminal)中输入
ssh -T git@gitee.com
若返回 Hi XXX! You’ve successfully authenticated, but Gitee.com does not provide shell access. 内容,则证明添加成功。添加成功后,就可以使用SSH协议对仓库进行操作了。git push就不用输入密码了。
|