赞
踩
使用 git –version 测试是否安装
fhz@fhz-ThinkPad-X230:~/.ssh$ git --version
git version 1.9.1
如果没有安装,使用命令: sudo apt-get install git git-core 安装git
申请Github账号,接下来通过Ubuntu下的ssh-keygen命令创建公钥/私钥对:ssh-keygen -C “yourname@gmail.com” -f ~/.ssh/github
fhz@fhz-ThinkPad-X230:~$ ssh-keygen -C "rootfuhongzhu@163.com" -f ~/.ssh/github
Generating public/private rsa key pair.
/home/fhz/.ssh/github already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/fhz/.ssh/github.
Your public key has been saved in /home/fhz/.ssh/github.pub.
The key fingerprint is:
30:4a:8d:36:38:1f:e3:75:56:ee:bc:d5:09:be:f4:33 rootfuhongzhu@163.com
The key's randomart image is:
+--[ RSA 2048]----+
| . |
| . o o |
| o B = o . . |
| * * = o . o . |
| + S o + o |
| + o |
| . . E |
| o |
| |
+-----------------+
后将~/.ssh/github.pub公钥中的内容复制到剪贴板
fhz@fhz-ThinkPad-X230:~$ vi ~/.ssh/github.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC47Kp96pQwEcrzT5GPzJ8T6XorRa6me4tnUvLBE3 MsOd/TF+0WqGO86jRYbBnQ/7UZjH/r1CoMruOwKuYCYNdwlTkYmzzFqzPePC3svBiWe2DpCcsw2rtijqgEjfriqIa85bCb2rg4mFVSpB0Hakiuyuihtj7PaI80eL7nPDzuW4ip73EhA42evNfMm56YVUhpzlHcS2nda1dzPf8VKF93gJhKbACMx4qQuP0ox3e2SoAoj3rb2FUcCqhp9LCKgq7oapt8mLvBg4N3ifbQXghshRGALuRvN/AYy9+pzFPfc4g5XO004vqFMMlKxEEEiivAWO1cX62AXmMNT rootfuhongzhu@163.com
将正确的公钥(上述内容)内容拷贝到网页GitHub中Setting的SSH keys文本框中,并为这个ssh起个名字,得到类似下面信息
SSH keys
This is a list of SSH keys associated with your account. Remove any keys that you do not recognize.
- SSH fhz Fingerprint: 30:4a:8d:36:38:1f:e3:75:09:be:f4:33 Added on — Last used within the last day
Check out our guide to generating SSH keys or troubleshoot common SSH Problems.
设置成功后,用Terminal用ssh命令访问GitHub
fhz@fhz-ThinkPad-X230:~/.ssh$ ssh -T git@github.com
Hi wuqiufeng! You've successfully authenticated, but GitHub does not provide shell access.
查看帮助文档 git 命令+-h
fhz@fhz-ThinkPad-X230:~$ git add -h
用法:git add [选项] [--] <路径规则>...
-n, --dry-run 演习
-i, --interactive 交互式拣选
-p, --patch 交互式挑选数据块
-e, --edit 编辑当前差异并应用
-f, --force 允许添加忽略的文件
-u, --update 更新已跟踪的文件
-N, --intent-to-add 只记录,该路径稍后再添加
-A, --all 添加所有改变的已跟踪文件和未跟踪文件
--ignore-removal 忽略工作区中移除的路径(和 --no-all 相同)
--refresh 不添加,只刷新索引
--ignore-errors 跳过因出错不能添加的文件
--ignore-missing 检查在演习模式下文件(即使不存在)是否被忽略
在github建立空项目,初始化本地的git代码环境git init
fhz@fhz-ThinkPad-X230:~/git$ git init
初始化空的 Git 仓库于 /home/fhz/git/.git/
给git添加一个 项目的描述文档 README.md,将 README.md设置为提交状态git add
fhz@fhz-ThinkPad-X230:~/git$ echo "# test" >> README.md
fhz@fhz-ThinkPad-X230:~/git$ git add README.md
fhz@fhz-ThinkPad-X230:~/git$ git status
位于分支 master
初始提交
新文件: README.md
提交到远程的git仓库中git commit
fhz@fhz-ThinkPad-X230:~/git$ git commit README.md -m"first commit README.md"
[master (根提交) 5f6b88c] first commit README.md
1 file changed, 3 insertions(+)
create mode 100644 README.md
fhz@fhz-ThinkPad-X230:~/git$ git status
位于分支 master
无文件要提交,干净的工作区
只在第一次使用要将本地跟远端建立连接, xxx.git在github上已建立好的项目
fhz@fhz-ThinkPad-X230:~/git$ git remote add origin git@github.com:wuqiufeng/xxx.git
提交新添加的代码 到远程 git push
fhz@fhz-ThinkPad-X230:~/git$ git push -u origin master
Warning: Permanently added the RSA host key for IP address '192.30.253.113' to the list of known hosts.
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 460 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
To git@github.com:wuqiufeng/test.git
* [new branch] master -> master
分支 master 设置为跟踪来自 origin 的远程分支 master。
下载一个分支的代码 git clone
fhz@fhz-ThinkPad-X230:~/test/test$ git clone -b master git@github.com:wuqiufeng/test.git
正克隆到 'test'...
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
接收对象中: 100% (6/6), done.
检查连接... 完成。
代码出现冲突
git pull
如果代码出现冲突 git diff filename
git stash 先回复本地到上一个版本
git pull 将最新的文件 拉到本地
git stash pop 将本地最新的修改回复, 将最新的修改合并到 本地文件中
修改本地文件 找到<<<<<的冲突代码
修改完之后, git pull, git commit, git pull ,git push
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。