1、git安装
ubuntu下安装git非常简单,直接使用apt-get命令即可。
sudo apt-get install git
2、查看git安装是否成功
安装完成后在终端中可以输入git命令来查看git是否安装成功。
git
或者使用
git --version
来查看git的安装版本。
3、配置git
在终端中依次输入下述命令,引号里面的内容替换成你的用户信息。
git config --global user.name "robin"
git config --global user.email "chou_robin@hotmail.com"
git config --list
ssh-keygen -C 'you email address@gmail.com' -t rsa
4、在github端添加密钥
上述命令执行完成之后就会在ubuntu系统中产生一个SSH的密钥。进入到home目录下,打开id_rsa.pub文件,将此文件中的内容拷贝到github的配置项中。这一步十分关键
5、克隆项目
从github上clone一个项目到本地:
git clone git@github.com:bzhou830/DataStruct.git
Cloning into 'DataStruct'...
Warning: Permanently added the RSA host key for IP address '192.30.252.122' to the list of known hosts.
remote: Counting objects: 61, done.
remote: Total 61 (delta 0), reused 0 (delta 0), pack-reused 61
Receiving objects: 100% (61/61), 19.67 KiB | 0 bytes/s, done.
Resolving deltas: 100% (8/8), done.
Checking connectivity... done.
6、源码修改后查看git状态
修改源码后,查看修改状态
git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: String.cpp
modified: main.cpp
Untracked files:
(use "git add <file>..." to include in what will be committed)
Makefile
str
no changes added to commit (use "git add" and/or "git commit -a")
7、添加新文件到仓库
添加修改
git add Makefile
git add str
git commit -m "add"
8、推送源码到github源码仓库
推送源码到github源码仓库:
git push origin master
Counting objects: 7, done.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 13.38 KiB | 0 bytes/s, done.
Total 5 (delta 1), reused 0 (delta 0)
To git@github.com:bzhou830/DataStruct.git
8a89341..1cc6526 master -> master