1、常用命令

2、远程管理

git clone https://github.com/guohongze/adminset.git
git pull     #这个是进行过clone,再次拉取远程仓库需要用pull,会直接合并本地分支
git fetch    #代码下载不会合并当前本地分支
git push origin master
git remote
git remote –v
git remote add xxx http://xxx
git remote show origin
git remote rename pb paul
git tag -a v1.0 -m ‘abc’

2.1、将github 代码 clone 到本地

[root@linux-node5 ~]# git clone https://github.com/sunrisenan/shell.git
Cloning into 'shell'...
remote: Enumerating objects: 195, done.
remote: Counting objects: 100% (195/195), done.
remote: Compressing objects: 100% (171/171), done.
remote: Total 195 (delta 16), reused 193 (delta 14), pack-reused 0
Receiving objects: 100% (195/195), 50.07 KiB | 0 bytes/s, done.
Resolving deltas: 100% (16/16), done.
Checking connectivity... done.

2.2、修改并提交至本地仓库

[root@linux-node5 ~]# ll
total 4
drwxr-xr-x 17 root root 4096 Mar 29 10:05 shell
[root@linux-node5 ~]# cd shell/
[root@linux-node5 shell]# git branch
* master
[root@linux-node5 shell]# echo "nihao" >> README.md
[root@linux-node5 shell]# git add .

[root@linux-node5 shell]# git log
commit ca3ab712a83e348156b2511cf0e4b93f393923f6
Author: 1210353303@qq.com <1210353303@qq.com>
Date:   Fri Mar 8 15:34:33 2019 +0800

    [更新] gawk进阶

commit 0e37f141c772a31fa5ccc76f328cdfd22c0df06e
Author: 1210353303@qq.com <1210353303@qq.com>
Date:   Fri Mar 8 15:19:27 2019 +0800

    [更新] shell初次更新
[root@linux-node5 shell]# git commit -m "readme update"
[master a4da598] readme update
 1 file changed, 1 insertion(+)

2.3、查看可以推送的远程仓库地址

[root@linux-node5 shell]# git remote
origin
[root@linux-node5 shell]# git remote -v
origin    https://github.com/sunrisenan/shell.git (fetch)
origin    https://github.com/sunrisenan/shell.git (push)

2.4、推送代码至远程仓库

[root@linux-node5 shell]# git push origin master 
Username for 'https://github.com': 1210353303@qq.com   #输入github账号
Password for 'https://1210353303@qq.com@github.com':   #输入github密码
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 301 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/sunrisenan/shell.git
   ca3ab71..a4da598  master -> master

2.5、查看远程仓库详情

[root@linux-node5 shell]# git remote show origin
* remote origin
  Fetch URL: https://github.com/sunrisenan/shell.git
  Push  URL: https://github.com/sunrisenan/shell.git
  HEAD branch: master
  Remote branches:
    develop tracked
    master  tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

这个命令列出了当你在特定的分支上执行 git push 会自动地推送到哪一个远程分支。 它也同样地列出了哪些远程分支不在你的本地,哪些远程分支已经从服务器上移除了,还有当你执行 git pull 时哪些分支会自动合并。

2.6、添加远程仓库地址

需求:当前有个github仓库,再添加一个gitlab仓库

[root@linux-node5 shell]# git remote 
origin
[root@linux-node5 shell]# git remote -v
origin    https://github.com/sunrisenan/shell.git (fetch)
origin    https://github.com/sunrisenan/shell.git (push)
[root@linux-node5 shell]# 
[root@linux-node5 shell]# 
[root@linux-node5 shell]# git remote add gitlab http:192.168.6.243/shell.git
[root@linux-node5 shell]# git remote
gitlab
origin
[root@linux-node5 shell]# git remote -v
gitlab    http:192.168.6.243/shell.git (fetch)
gitlab    http:192.168.6.243/shell.git (push)
origin    https://github.com/sunrisenan/shell.git (fetch)
origin    https://github.com/sunrisenan/shell.git (push)

打标签:
[root@linux-node5 shell]# git tag
[root@linux-node5 shell]# git tag -a v1.0 -m “feature finished”
[root@linux-node5 shell]# git tag
v1.0

文档更新时间: 2019-03-29 10:45   作者:李延召