MAC上Git安裝與GitHub使用


目錄

  • 安裝git
  • 創建ssh_key、配置git
  • 提交本地項目到Github

一、安裝Git

MAC 上安裝Git主要有兩種方式

首先檢查電腦是否安裝Git,終端輸入

git

安裝過則會輸出:

deyou@deyoudeMacBook-Pro .ssh % git

usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]

           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]

           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]

           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]

           <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)

   clone      Clone a repository into a new directory

   init       Create an empty Git repository or reinitialize an existing one 

work on the current change (see also: git help everyday)

   add        Add file contents to the index

   mv         Move or rename a file, a directory, or a symlink

   reset      Reset current HEAD to the specified state

   rm         Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)

   bisect     Use binary search to find the commit that introduced a bug

   grep       Print lines matching a pattern

   log        Show commit logs

   show       Show various types of objects

   status     Show the working tree status

grow, mark and tweak your common history

   branch     List, create, or delete branches

   checkout   Switch branches or restore working tree files

   commit     Record changes to the repository

   diff       Show changes between commits, commit and working tree, etc

   merge      Join two or more development histories together

   rebase     Reapply commits on top of another base tip

   tag        Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)

   fetch      Download objects and refs from another repository

   pull       Fetch from and integrate with another repository or a local branch

   push       Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some

concept guides. See 'git help <command>' or 'git help <concept>'

to read about a specific subcommand or concept.

1、通過homebrew安裝Git

  • 1、未安裝homebrew,需安裝homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • 2、安裝git
brew install git

2、通過安裝包下載安裝

  官網下載鏈接:https://git-scm.com/downloads

  百度網盤鏈接: https://pan.baidu.com/s/1fRQd_faHXbXJfjaDwdRRZQ  密碼: bt1j

二、創建SSH Key、配置Git

  • 1、設置username和email(github每次commit都會記錄他們)
git config --global user.name "DeyouKong"
git config --global user.email "1026328997@qq.com"
  • 2、通過終端命令創建ssh key
ssh-keygen -t rsa -C "1026328997@qq.com"
1026328997@qq.com為我的郵箱,回車可見到一下輸出

deyou@deyoudeMacBook-Pro ~ % ssh-keygen -t rsa -C "1026328997@qq.com"

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/deyou/.ssh/id_rsa): deyou_ssh_key

Enter passphrase (empty for no passphrase): 

Enter same passphrase again: 

Your identification has been saved in deyou_ssh_key.

Your public key has been saved in deyou_ssh_key.pub.

The key fingerprint is:

SHA256:qjvYDpyCL+Tbocbrh1eMlj/XO+vSBQb2g9w1b1R4eLI 1026328997@qq.com

The key's randomart image is:

+---[RSA 2048]----+

|              +. |

|       o   o = o |

|      o = . + =  |

|       o *   E   |

|    +   S o .    |

|.o = o .   .     |

|* *+o . o .      |

|.B++++ o +       |

|o**o+oo o++      |

+----[SHA256]-----+

deyou@deyoudeMacBook-Pro ~ % ls 

Desktop Downloads MeiCloud Music Public deyou_ssh_key.pub

Documents Library Movies Pictures deyou_ssh_key jmeter.log

成功的話會在~/下生成.ssh文件夾,進去,打開deyou_ssh_key.pub,復制里面的key

終端查看deyou_ssh_key.pub文件

cat deyou_ssh_key.pub

3、登錄GitHub(默認你已經注冊了GitHub賬號),添加ssh key,點擊Settings,如圖

4、鏈接驗證

ssh -T git@github.com

終端輸出結果

deyou@deyoudeMacBook-Pro ~ % ssh -T git@github.com
Hi DeyouKong!You've successfully authenticated, but GitHub does not provide shell access.

三、提交本地項目到Github

  • 1、在GitHub上新創建一個 repository或者Start a Project,填寫項目信息,如圖:

 

 

點擊Create repository,就創好一個工程了。

  • 2、提交文件

1、倉庫初始化

git init

2、連接倉庫

git remote add origin https://github.com/DeyouKong/httprunner.git  (更改為自己的工程地址)

3、查看狀態

git status

4、將文件添加到暫存區

git add 狀態里的新文件 (.為全部文件)

5、將文件添加到倉庫

git commit -m'相關注釋文字'

 6、將本地代碼提交到遠程倉庫

git push origin master

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM