mac上git安裝與github基本使用


目錄

  • 安裝git
  • 創建ssh key、配置git
  • 提交本地項目到GitHub

一、安裝Git

MAC安裝Git

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

git

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

二、創建ssh key、配置git

  • 1、設置username和email(github每次commit都會記錄他們)
git config --global user.name "puqunzhu"
git config --global user.email "984471751@qq.com"
  • 2、通過終端命令創建ssh key
ssh-keygen -t rsa -C "984471751@qq.com"

984471751@qq.com是我的郵件名,回車會有以下輸出

qunzhudeMacBook-Air:git qunzhupu$ ssh-keygen -t rsa -C "984471751@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/qunzhupu/.ssh/id_rsa): 
/Users/qunzhupu/.ssh/id_rsa already exists.
Overwrite (y/n)? n

由於這里我原來已經創建過,這里我選n,沒有創建過的,會要求確認路徑和輸入密碼,我們這使用默認的一路回車就行。成功的話會在~/下生成.ssh文件夾,進去,打開id_rsa.pub,復制里面的key。
終端查看.ssh/id_rsa.pub文件

open .ssh/id_rsa.pub

回車后,就會新彈出一個終端,然后復制里面的key。
或者用cat命令查看

cat .ssh/id_rsa.pub
  • 3、登錄GitHub(默認你已經注冊了GitHub賬號),添加ssh key,點擊Settings,點擊New SSH key,添加key
  • 4、鏈接驗證
ssh -T git@github.com

終端輸出結果

qunzhudeMacBook-Air:git qunzhupu$ ssh -T git@github.com
Enter passphrase for key '/Users/qunzhupu/.ssh/id_rsa': 
Hi puqunzhu! You've successfully authenticated, but GitHub does not provide shell access.

三、提交本地項目到GitHub

  • 1、在GitHub上新創建一個 repository或者Start a Project
  • 2、填寫項目信息,點擊Create repository,就創好一個工程了。
  • 3、Clone工程到本地,首先復制ssh 地址
    打開終端,這里只是測試,我想把工程克隆在桌面,首先在終端中切換路徑到桌面,輸入以下命令:
cd /Users/puqunzhu/Desktop/

然后克隆項目,終端輸入

git clone https://github.com/puqunzhu/git.git

https://github.com/puqunzhu/git.git是剛剛復制的ssh路徑

  • 4、創建一個工程,保存的路徑為剛剛克隆下來的git文件夾下
  • 5、提交修改,首先切換到git文件路徑
cd /Users/puqunzhu/Desktop/git

然后輸入:

//文件添加到倉庫(.代表提交所有文件)
git add .
//把文件提交到倉庫
git commit -m "First Commit"
//上傳到github
git push

查看GitHub上的項目,git已經上傳成功啦

git clone https://github.com/puqunzhu/maoyantop100.git
cd maoyantop100/
echo "# maoyantop100" >> README.md
git init
git add README.md 
git commit -m "first commit"
git remote add orgin https://github.com/puqunzhu/maoyan100.git
git push -u origin master


免責聲明!

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



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