[root@localhost /]# yum install git
[root@localhost /]# git config --global user.name "Your Name"
[root@localhost /]# git config --global user.email "email@example.com"
[root@localhost /]# mkdir uter
[root@localhost /]# cd uter
[root@localhost uter]# git init
初始化空的 Git 版本库于 /uter/.git/
[root@localhost uter]# ls -ah
. .. .git
//前面几步操作我们已经成功安装了git并创建了一个版本库,如果需要把这个版本库取消那么直接把(.git)这个文件删除就可以了
[root@localhost uter]# rm -rf .git
//现在我们试试把文件上传到版本库
[root@localhost uter]# vim git.txt
[root@localhost uter]# git add git.txt
[root@localhost uter]# git status
# 位于分支 master
#
# 初始提交
#
# 要提交的变更:
# (使用 "git rm --cached <file>..." 撤出暂存区)
#
# 新文件: git.txt
#
[root@localhost uter]# git commit -m "linux test git"
[master(根提交) c87e19d] linux test git
1 file changed, 1 insertion(+)
create mode 100644 git.txt
[root@localhost uter]# git log //查看版本信息
//在这里我直接对接我github上的远程仓库[已经建好的]
[root@localhost uter]# git remote add origin https://github.com/xuedongyue/learngit.git
[root@localhost uter]# git merge origin/master
[root@localhost uter]# git push -u origin master
接下来我们回到浏览器返回 Github 创建的仓库刷新一下,就可以看到文件已上传到Github上:
查看当前的远程库:
[root@localhost uter]# git remote
[root@localhost uter]# git remote -v // -v 参数,可以看到每个别名的实际链接地址。
提取远程仓库:
1、从远程仓库下载新分支与数据
[root@localhost uter]# git fetch
//该命令执行完后需要执行git merge 远程分支到你所在的分支。
2、从远端仓库提取数据并尝试合并到当前分支
[root@localhost uter]# git pull
//该命令就是在执行 git fetch 之后紧接着执行 git merge 远程分支到你所在的任意分支。
假设你配置好了一个远程仓库,并且你想要提取更新的数据,你可以首先执行
git fetch [alias] 告诉 Git 去获取它有你没有的数据,然后你可以执行
git merge [alias]/[branch] 以将服务器上的任何更新(假设有人这时候推送到服务器了)合并到你的当前分支。
[root@localhost uter]# git fetch origin
[root@localhost uter]# git merge origin/master (远程库名/分支名)
推送到远程仓库:
[root@localhost uter] git push origin master
推荐一个网站,关于git介绍的非常详细全面:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000