github远程仓库常用命令实战

Administrator@USER-QKAROI6I4J MINGW64 /c/opt/demo2 (master)
$ ssh-keygen -t rsa -C "[email protected]"
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:[email protected]
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 [email protected]
  • 测试是否连接到github
Administrator@USER-QKAROI6I4J MINGW64 ~/.ssh
$ ssh -T [email protected]
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  [email protected]: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 [email protected]: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 [email protected]: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 ..." 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 ..." 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 [email protected]:chenliang1234576/repodemo1.git
   f7ec5bb..cc1f4cd  master -> master

你可能感兴趣的:(github远程仓库常用命令实战)