FAIRYFAR-INTERNAL
 
  FAIRYFAR-INTERNAL  |  SITEMAP  |  ABOUT-ME  |  HOME  
您的足迹: Git创建远程仓库
Git创建远程仓库

在Linux环境下,在git正确安装的情况下。创建一个可以远程访问的仓库过程:

准备目录

snippet.bash
[yz@bogon ~]$ mkdir git_demo
[yz@bogon ~]$ cd git_demo/
[yz@bogon git_demo]$ echo "Hello" > Readme.txt
[yz@bogon git_demo]$ pwd
/home/yz/git_demo

创建一个本地git仓库

snippet.bash
[yz@bogon git_demo]$ git init
[yz@bogon git_demo]$ git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint:   git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint:   git branch -m <name>
Initialized empty Git repository in /home/yz/git_demo/.git/

提交(初始版的)文件

snippet.bash
[yz@bogon git_demo]$ git add --all
[yz@bogon git_demo]$ git commit -m "首次提交"
[master (root-commit) 11d2665] 首次提交
 1 file changed, 1 insertion(+)
 create mode 100644 Readme.txt

可以看一下git log:

snippet.bash
[yz@bogon git_demo]$ git log
commit 11d2665a7f75f6e983040da1e35eb9c1c526ca91 (HEAD -> master)
Author: yz <yz@sb.com>
Date:   Thu Dec 9 18:56:25 2021 +0800
 
    首次提交

添加一个远程仓库

snippet.bash
[yz@bogon git_demo]$ git remote add origin ssh://yz@127.0.0.1/~/git_demo

如果报告类似以下错误:

ssh: connect to host 127.0.0.1 port 22: Connection refused
fatal: The remote end hung up unexpectedly

则需要安装 openssl-server

将本地仓库的master分支push到远程分支

snippet.bash
[yz@bogon git_demo]$ git push origin master
yz@127.0.0.1's password:
Everything up-to-date

验证远程仓库

snippet.bash
[yz@bogon ~]$ mkdir test
[yz@bogon ~]$ cd test/
[yz@bogon test]$ git clone ssh://yz@127.0.0.1/~/git_demo
Cloning into 'git_demo'...
yz@127.0.0.1's password:
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
 
[yz@bogon test]$ cd git_demo/
[yz@bogon git_demo]$ git branch
* master
[yz@bogon git_demo]$ git log
commit 11d2665a7f75f6e983040da1e35eb9c1c526ca91 (HEAD -> master, origin/master, origin/HEAD)
Author: yz <yz@sb.com>
Date:   Thu Dec 9 18:56:25 2021 +0800
 
    首次提交


打赏作者以资鼓励: