GitHub Clone and Push

GitHub Clone and Push

在Github创建私有仓库“blog”

*登陆Github后,直接点New repository来创建一个新的私有仓库,比如:我创建了一个blog的仓库。

clone代码到本地电脑

在本地电脑,打开Git命令行,进入希望放置blog的目录,运行“git clone git@github.com:zhenzhang20/blog.git” 来clone代码到本地。其中clone的地址可以在仓库中看到:

  • 过程中可能遇到报错:
zz@Zhen MINGW64 /d/develop/www
$ git clone git@github.com:zhenzhang20/blog.git
Cloning into 'blog'...
ssh: connect to host github.com port 22: Connection refused
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
  • 遇到22端口报错,可能是网络原因,先运行“ssh -T -p 22 git@ssh.github.com”检查22端口是否可以使用(默认是22端口,则可以使用“ssh -T git@github.com”):
    $ ssh -T git@github.com
    ssh: connect to host github.com port 22: Connection refused
    
  • 如果22端口报“Connection refused”,则可以尝试修改使用433端口,依旧先检查433端口是否可以使用,运行“ ssh -T -p 443 git@ssh.github.com” 检查433端口是否可用:

    zz@Zhen MINGW64 /
    $ ssh -T -p 443 git@ssh.github.com
    The authenticity of host '[ssh.github.com]:443 ([20.205.243.160]:443)' can't be established.
    ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
    This host key is known by the following other names/addresses:
      ~/.ssh/known_hosts:1: github.com
    Are you sure you want to continue connecting (yes/no/[fingerprint])?
  • 若433端口可用,则在.ssh 目录创建文件:config,并编辑:~/.ssh/config, 文件内容为:

    Host github.com
    Hostname ssh.github.com
     Port 443
  • 遇到“Failed to connect to ** after 2243 ms: Couldn’t connect to server”报错一般为网络问题,需要检查是否能正常访问Github:

    zz@Zhen MINGW64 /d/develop/www
    $ git clone <https://github.com/zhenzhang20/blog.git>
    Cloning into 'blog'...
    fatal: unable to access '<https://github.com/zhenzhang20/blog.git/>': Failed to connect to github.com port 443 after 2243 ms: Couldn't connect to server
  • 再次运行“ssh -T git@github.com” 检查是否可以连接成功。显示内容包括“You’ve successfully authenticated”则表示成功。

    zz@Zhen MINGW64 /
    $ ssh -T git@github.com
    The authenticity of host '[ssh.github.com]:443 ([20.205.243.160]:443)' can't be established.
    ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
    This host key is known by the following other names/addresses:
      ~/.ssh/known_hosts:1: github.com
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    Warning: Permanently added '[ssh.github.com]:443' (ED25519) to the list of known hosts.
    Hi zhenzhang20! You've successfully authenticated, but GitHub does not provide shell access.
  • 可以成功连接后,进行clone代码到本地:

    zz@Zhen MINGW64 /d/develop/www
    $ git clone git@github.com:zhenzhang20/blog.git
    Cloning into 'blog'...
    remote: Enumerating objects: 8, done.
    remote: Counting objects: 100% (8/8), done.
    remote: Compressing objects: 100% (4/4), done.
    remote: Total 8 (delta 0), reused 5 (delta 0), pack-reused 0
    Receiving objects: 100% (8/8), done.

在下载的blog目录中添加一个“add.md”文件,并尝试提交到Github仓库

  • 进入blog目录,会自动显示当前仓库的branch为main
  • 添加新增的文件、增加提交注释、提交到远程仓库
    git add .
    git commit -m 'initial'
    git push origin main
  • 过程中可能报错:
    git push origin main
    fatal: unable to access 'https://github.com.zhenzhang20/blog.git/': Recv failure: Connection was reset
  • 解决方法,运行:
    git config --global --unset http.proxy
    git config --global --unset https.proxy

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!