GitHub-创建仓库与本地同步
程序员文章站
2024-01-11 22:57:58
1. 在Linux上安装Git 2. 本地创建ssh-key信息 3. 在GitHub上添加SSH Keys信息 4. 在GitHub上新建仓库并本地克隆仓库 4.1. GitHub新建仓库 4.2. 本地克隆GitHub仓库 5. 本地建仓库并同步到GitHub上 5.1. 本地建仓库 5.3. ......
1. 在linux上安装git
1 [root@mini05 ~]# yum install -y git 2 ………………
2. 本地创建ssh-key信息
1 [root@mini05 ~]# ssh-keygen -t rsa 2 generating public/private rsa key pair. 3 enter file in which to save the key (/root/.ssh/id_rsa): 4 created directory '/root/.ssh'. 5 enter passphrase (empty for no passphrase): 6 enter same passphrase again: 7 your identification has been saved in /root/.ssh/id_rsa. 8 your public key has been saved in /root/.ssh/id_rsa.pub. 9 the key fingerprint is: 10 sha256:acvhut11cmkdal1qzsrl3x23oyul9cd7+klffw30clm root@mini05 11 the key's randomart image is: 12 +---[rsa 2048]----+ 13 | . . | 14 | . o o o.o| 15 | . b * = . . *=| 16 | * o o = . .eb| 17 | . o . s . o .+| 18 | + o . . . o.o| 19 | . + . . .+ o+| 20 | . . . o..o o| 21 | . . . oo o.| 22 +----[sha256]-----+ 23 [root@mini05 ~]# ll -d .ssh/ 24 drwx------ 2 root root 38 sep 17 22:26 .ssh/ 25 [root@mini05 ~]# cd .ssh/ 26 [root@mini05 .ssh]# ll 27 total 8 28 -rw------- 1 root root 1679 sep 17 22:26 id_rsa 29 -rw-r--r-- 1 root root 393 sep 17 22:26 id_rsa.pub 30 [root@mini05 .ssh]# cat id_rsa.pub 31 ssh-rsa aaaab3nzac1yc2exxxxdaqabaaabaqdzzmxpdvvntszyxxxxxkkkk/jporl9qc9yn/ydrfbrroxxc0lz0ote8asbmmgvtyexs01+apwyuqutm+pne1bexhkkybxa3etginnnxhjocji/y9qsokii+nphkcpm/wrmaip6eh1by2v60ltu0cyultdienfc5d1t84fymyrrf6u1r27utjixaubwcojyzpmog1rwqp8oex3gq1z5h7gmtkquu/gkcmvpqoxmy+uwytrbd3nmdd2gklgg6oadsw01jafjjgedgxsb/z1zvuh46mgx9zju94b+bfqhbx8e8qmqskrkmzhl09lzqhkvyosvtbbcemhf123k2x8iledrr4f/ root@mini05
3. 在github上添加ssh keys信息
4. 在github上新建仓库并本地克隆仓库
4.1. github新建仓库
git@github.com:zhanglianghhh/zhangtest.git
4.2. 本地克隆github仓库
1 [root@mini05 git_repository]# pwd # 注意目录 2 /opt/git_repository 3 [root@mini05 git_repository]# git clone git@github.com:zhanglianghhh/zhangtest.git 4 cloning into 'zhangtest'... 5 the authenticity of host 'github.com (192.30.253.113)' can't be established. 6 rsa key fingerprint is sha256:nthbg6kxupjwgl7e1igocspromtxdcarlvikw6e5sy8. 7 rsa key fingerprint is md5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48. 8 are you sure you want to continue connecting (yes/no)? yes # 如果是第一次连接,就会出现这种情况 9 warning: permanently added 'github.com,192.30.253.113' (rsa) to the list of known hosts. 10 remote: counting objects: 3, done. 11 remote: total 3 (delta 0), reused 0 (delta 0), pack-reused 0 12 receiving objects: 100% (3/3), done. 13 [root@mini05 git_repository]# ll 14 total 0 15 drwxr-xr-x 3 root root 35 sep 17 22:38 zhangtest
5. 本地建仓库并同步到github上
5.1. 本地建仓库
1 [root@mini05 gittest]# pwd 2 /opt/git_repository/gittest 3 [root@mini05 gittest]# git init 4 initialized empty git repository in /opt/git_repository/gittest/.git/ 5 [root@mini05 gittest]# ll -a 6 total 0 7 drwxr-xr-x 3 root root 18 oct 1 15:22 . 8 drwxr-xr-x 6 root root 67 oct 1 15:22 .. 9 drwxr-xr-x 7 root root 119 oct 1 15:22 .git 10 [root@mini05 gittest]# cat test.info 11 111 12 222 13 333 14 [root@mini05 gittest]# git add . # 添加到暂存区 15 [root@mini05 gittest]# git commit -m "add" # 提交到仓库 16 [master (root-commit) 1c47050] add 17 1 file changed, 3 insertions(+) 18 create mode 100644 test.info
5.3. github新建仓库
5.3. 本地仓库关联github
1 [root@mini05 gittest]# git remote add origin git@github.com:zhanglianghhh/gittest.git 2 [root@mini05 gittest]# git push -u origin master # 第一次提交时 后续提交: git push origin master 3 counting objects: 3, done. 4 writing objects: 100% (3/3), 220 bytes | 0 bytes/s, done. 5 total 3 (delta 0), reused 0 (delta 0) 6 remote: 7 remote: create a pull request for 'master' on github by visiting: 8 remote: https://github.com/zhanglianghhh/gittest/pull/new/master 9 remote: 10 to git@github.com:zhanglianghhh/gittest.git 11 * [new branch] master -> master 12 branch master set up to track remote branch master from origin.
6. git仓库的更新
6.1. github有更新之后本地更新仓库
1 [root@mini05 zhangtest]# pwd # 注意所在目录 2 /opt/git_repository/zhangtest 3 [root@mini05 zhangtest]# ll 4 total 4 5 -rw-r--r-- 1 root root 29 sep 17 23:11 readme.md 6 [root@mini05 zhangtest]# cat readme.md 7 # zhangtest 8 zhangtest 9 [root@mini05 zhangtest]# git pull # 本地更新 10 remote: counting objects: 3, done. 11 remote: total 3 (delta 0), reused 0 (delta 0), pack-reused 0 12 unpacking objects: 100% (3/3), done. 13 from github.com:zhanglianghhh/zhangtest 14 * branch head -> fetch_head 15 updating e730676..d4fb57e 16 fast-forward 17 readme.md | 1 + 18 1 file changed, 1 insertion(+) 19 [root@mini05 zhangtest]# cat readme.md 20 # zhangtest 21 zhangtest 22 张三
6.2. 本地更新并提交到本地仓库
1 [root@mini05 zhangtest]# pwd 2 /opt/git_repository/zhangtest 3 [root@mini05 zhangtest]# git status # 查看仓库当前的状态----可见文件没有修改,也没有需要提交的 4 # on branch master 5 # your branch is ahead of 'origin/master' by 1 commit. 6 # (use "git push" to publish your local commits) 7 # 8 nothing to commit, working directory clean 9 [root@mini05 zhangtest]# cat readme.md # 更新的文件 10 # zhangtest 11 zhangtest 12 张三 13 git is a distributed version control system. # 新增的行 14 git is free software. # 新增的行 15 [root@mini05 zhangtest]# git status # 查看仓库当前的状态----可见文件有修改,但是没有提交到本地仓库 16 # on branch master 17 # your branch is ahead of 'origin/master' by 1 commit. 18 # (use "git push" to publish your local commits) 19 # 20 # changes not staged for commit: 21 # (use "git add <file>..." to update what will be committed) 22 # (use "git checkout -- <file>..." to discard changes in working directory) 23 # 24 # modified: readme.md 25 # 26 no changes added to commit (use "git add" and/or "git commit -a") 27 [root@mini05 zhangtest]# git diff readme.md # 查看仓库中的文件和当前文件的区别 28 diff --git a/readme.md b/readme.md 29 index a1c15c2..4346fe7 100644 30 --- a/readme.md 31 +++ b/readme.md 32 @@ -1,3 +1,5 @@ 33 # zhangtest 34 zhangtest 35 张三 36 +git is a distributed version control system. 37 +git is free software. 38 [root@mini05 zhangtest]# git add readme.md # 将文件内容添加到索引(将修改添加到暂存区)。也就是将要提交的文件的信息添加到索引库中。 39 # git add . 说明:如果是 . 表示当前目录 40 [root@mini05 zhangtest]# git status # 查看仓库当前的状态----有文件需要提交 41 # on branch master 42 # your branch is ahead of 'origin/master' by 1 commit. 43 # (use "git push" to publish your local commits) 44 # 45 # changes to be committed: 46 # (use "git reset head <file>..." to unstage) 47 # 48 # modified: readme.md 49 # 50 [root@mini05 zhangtest]# git commit -m "add info" # 提交到本地仓库 51 [master 65a58f2] add info 52 1 files changed, 2 insertions(+) 53 create mode 100644 test.info 54 [root@mini05 zhangtest]# git status # 查看仓库当前的状态----可见文件没有修改,也没有需要提交的 55 # on branch master 56 # your branch is ahead of 'origin/master' by 2 commits. 57 # (use "git push" to publish your local commits) 58 # 59 nothing to commit, working directory clean
6.3. 本地仓库推送到git远程仓库
1 [root@mini05 zhangtest]# git push origin master 2 counting objects: 5, done. 3 delta compression using up to 4 threads. 4 compressing objects: 100% (3/3), done. 5 writing objects: 100% (3/3), 360 bytes | 0 bytes/s, done. 6 total 3 (delta 1), reused 0 (delta 0) 7 remote: resolving deltas: 100% (1/1), completed with 1 local object. 8 to git@github.com:zhanglianghhh/zhangtest.git 9 3b7db1c..c752e64 master -> master
上一篇: 仿dedecms下拉分页样式修改的thinkphp分页类实例
下一篇: nginx*享内存的使用