美文网首页
github远程仓库常用命令实战

github远程仓库常用命令实战

作者: 福如四海 | 来源:发表于2019-06-02 19:06 被阅读0次
  • 创建ssh key
    ssh-keygen -t rsa -C "email@example.com"

  • 生成ssh的秘钥

Administrator@USER-QKAROI6I4J MINGW64 /c/opt/demo2 (master)
$ ssh-keygen -t rsa -C "test@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Created directory '/c/Users/Administrator/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Passphrases do not match.  Try again.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:test@163.com
The key's randomart image is:
+---[RSA 2048]----+
|             .+..|
|             +E= |
|            o.o.+|
|      .  o ...++o|
|     o .S =  *oo.|
|      o .+. O.B. |
|     .  .oo* B.  |
|      . +=oo.    |
|       oo*O+.    |
+----[SHA256]-----+

Administrator@USER-QKAROI6I4J MINGW64 /c/opt/demo2 (master)
$ pwd
/c/opt/demo2
  • 切换到密钥目录
Administrator@USER-QKAROI6I4J MINGW64 /c/opt/demo2 (master)
$ cd /c/Users/Administrator/.ssh

Administrator@USER-QKAROI6I4J MINGW64 ~/.ssh
$ ls
id_rsa  id_rsa.pub

Administrator@USER-QKAROI6I4J MINGW64 ~/.ssh
$ ll
total 5
-rw-r--r-- 1 Administrator 197121 1766 六月  2 09:35 id_rsa
-rw-r--r-- 1 Administrator 197121  406 六月  2 09:35 id_rsa.pub
  • 查看密钥文件
Administrator@USER-QKAROI6I4J MINGW64 ~/.ssh
$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDEcQ1jpXSIHFrTrBL4U5BEiDcqw4Qo6WMY7R/p6On

+6mgwUSHyJSPg5xvR5g2lLkQhWdC56knFqrZcPIukcedwWooQ5aYn84FaKtULHZxUEju7nJWLTHZqNk/YddTu65AwV

+CyVroxqByrUAE6r80s6pX6YXoS83b55hNPSM1jYXS4nvJTe3kCrHiM9wCm8uKYljxSaoeK/QoyPO6xg7Cm0RNlu5+S

3LQc5FJgh6FEhhLJaNzI/wo36A3/O/ORt9+Bfpt2PbeAag04xqT7/ekDkunTG8iYYxDHFcbcFmfjgMkTTiV8jPyDIcr

viIXld56gXx0KUMWMKN7CJZoKFWxV test@163.com
  • 测试是否连接到github
Administrator@USER-QKAROI6I4J MINGW64 ~/.ssh
$ ssh -T git@github.com
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
Enter passphrase for key '/c/Users/Administrator/.ssh/id_rsa':
Hi chenliang1234576! You've successfully authenticated, but GitHub does not provide shell 

access.
 
  • 添加远程仓库
    切换到本地仓库,输入以下命令将该仓库关联到github上
Administrator@USER-QKAROI6I4J MINGW64 /c/opt/repodemo2 (master)
$ git remote add origin  git@github.com:test/repodemo2.git
  • 将本地仓库推送到github上
Administrator@USER-QKAROI6I4J MINGW64 /c/opt/repodemo2 (master)
$ git push -u origin master
Warning: Permanently added the RSA host key for IP address '113.229.188.59' to the list of 

known hosts.
Enter passphrase for key '/c/Users/Administrator/.ssh/id_rsa': 123456
Counting objects: 3, done.
Writing objects: 100% (3/3), 235 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:test/repodemo2.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

克隆github中的项目

Administrator@USER-QKAROI6I4J MINGW64 /c/opt/clone_demo1
$ git clone git@github.com:chenliang1234576/repodemo1.git
Cloning into 'repodemo1'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 10 (delta 1), reused 9 (delta 0), pack-reused 0
Receiving objects: 100% (10/10), done.
Resolving deltas: 100% (1/1), done.
Checking connectivity... done.
  
Administrator@USER-QKAROI6I4J MINGW64 /c/opt/clone_demo1/repodemo1 (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
  • 本地仓库中增加内容,并且提交到github中
Administrator@USER-QKAROI6I4J MINGW64 /c/opt/clone_demo1/repodemo1 (master)
$ echo "clone demo" >> clone.txt
  
Administrator@USER-QKAROI6I4J MINGW64 /c/opt/clone_demo1/repodemo1 (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        clone.txt

nothing added to commit but untracked files present (use "git add" to track)

Administrator@USER-QKAROI6I4J MINGW64 /c/opt/clone_demo1/repodemo1 (master)
$ git add clone.txt
warning: LF will be replaced by CRLF in clone.txt.
The file will have its original line endings in your working directory.

Administrator@USER-QKAROI6I4J MINGW64 /c/opt/clone_demo1/repodemo1 (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   clone.txt


Administrator@USER-QKAROI6I4J MINGW64 /c/opt/clone_demo1/repodemo1 (master)
$ git commit -m " clone commit 001"
[master cc1f4cd]  clone commit 001
warning: LF will be replaced by CRLF in clone.txt.
The file will have its original line endings in your working directory.
 1 file changed, 1 insertion(+)
 create mode 100644 clone.txt

Administrator@USER-QKAROI6I4J MINGW64 /c/opt/clone_demo1/repodemo1 (master)
  • 提交到github中
$ git push
warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 280 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:chenliang1234576/repodemo1.git
   f7ec5bb..cc1f4cd  master -> master

相关文章

  • Git常用命令集合

    Git 常用命令: 远程仓库相关命令检出仓库:$ git clone git://github.com/jque...

  • Git操作记录

    Git的使用常用命令GitHub远程仓库 Git的使用 常用命令 创建仓库 添加命令 提交命令 查看状态 查看修改...

  • Github

    Github使用教程一Github使用教程二Github使用教程三 Git常用命令Git之使用GitHub搭建远程仓库

  • Git 学习之路

    Git 常用命令: 从远程仓库获取项目到本地 $ git remote add origingit@github....

  • github远程仓库常用命令实战

    创建ssh keyssh-keygen -t rsa -C "email@example.com" 生成ssh的秘...

  • Github 快速上手实战教程

    Github 快速上手实战教程 1.首先要建立注册github账号2.创建远程仓库 点击创建,至此 Github ...

  • github | 仓库和分支管理

    1. 仓库管理 提示:仓库一般就指的是远程仓库即github的仓库.参阅:github 创建远程分支以及远程分支无...

  • Git 常用命令大全

    Git 常用命令大全 远程仓库相关命令 如果想把本地的某个分支test提交到远程仓库,并作为远程仓库的master...

  • git 基本用法

    注册github账号 用法 1. 远程仓库-->本地仓库(克隆) a)创建远程仓库gitDemob)从远程仓库克隆...

  • Git 远程仓库及分支管理

    前提:已有远程仓库项目 远程仓库信息: 来源:github远程仓库(YOUR_FORK)地址: https://g...

网友评论

      本文标题:github远程仓库常用命令实战

      本文链接:https://www.haomeiwen.com/subject/hvxfxctx.html