Git安裝與Gitee基本使用
- MAC上Git安裝與Gitee基本使用
-
- 安裝git
-
- 1、通過homebrew安裝Git
- 2、通過Xcode安裝
- 建立ssh key、配置git
-
- 4、連結驗證
- 5、下載下傳項目到本地
- Window下Git安裝使用
-
- Git安裝
- gitee托管項目代碼
- 送出本地項目到Gitee
MAC上Git安裝與Gitee基本使用
安裝git
MAC 上安裝Git主要有兩種方式
首先檢視電腦是否安裝Git,終端輸入:
git
安裝過則會輸出:
WMBdeMacBook-Pro:~ WENBO$ git
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --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
- 未安裝homebrew,需安裝homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- 安裝git
brew install git
2、通過Xcode安裝
直接從AppStore安裝Xcode,Xcode內建了Git,不過預設沒有安裝,你需要運作Xcode,選擇菜單“Xcode”->“Preferences”,在彈出視窗中找到“Downloads”,選擇“Command Line Tools”,點“Install”就可以完成安裝了。
建立ssh key、配置git
- 1、設定username和email(gitee每次commit都會記錄他們)
git config --global user.name "XXX"
git config --global user.email "[email protected]"
- 2、通過終端指令建立ssh key
ssh-keygen -t rsa -C "[email protected]"
[email protected]是你的郵件名,回車會有以下輸出
Last login: Sat Jan 6 14:12:16 on ttys000
WMBdeMacBook-Pro:~ WENBO$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/WENBO/.ssh/id_rsa):
/Users/XXX/.ssh/id_rsa already exists.
Overwrite (y/n)? n
WMBdeMacBook-Pro:~ XXX$
由于這裡我原來已經建立過,這裡我選n,沒有建立過的,會要求确認路徑和輸入密碼,我們這使用預設的一路回車就行。成功的話會在~/下生成.ssh檔案夾,進去,打開id_rsa.pub,複制裡面的key。
終端檢視.ssh/id_rsa.pub檔案
open .ssh/id_rsa.pub
回車後,就會新彈出一個終端,然後複制裡面的key。
或者用cat指令檢視
cat .ssh/id_rsa.pub
3、登入https://gitee.com/(預設你已經注冊了Gitee賬号),添加ssh key,點選Settings,如圖
點選“SSH公鑰”,如圖
添加key,如圖
4、連結驗證
ssh -T [email protected]
終端輸出結果
Last login: Sat Jan 6 14:42:55 on ttys000
WMBdeMacBook-Pro:~ XXX$ ssh -T [email protected]
Hi wenmobo! You’ve successfully authenticated, but Gitee does not provide shell access.
WMBdeMacBook-Pro:~ XXX$
說明已經連結成功。
5、下載下傳項目到本地
首先複制ssh位址
打開終端,這裡隻是測試,我想把工程克隆在指定目錄,首先在終端中切換路徑到指定目錄,輸入以下指令:
/e/workspace-python/test
然後克隆項目,終端輸入
git clone [email protected]:xiaolaifeng/sample.python.git
[email protected]:xiaolaifeng/sample.python.gitt是剛剛複制的ssh路徑。
終端完整輸出如下:
[email protected] MINGW64 /e/workspace-python/test
$ git clone [email protected]:xiaolaifeng/sample.python.git
Cloning into 'sample.python'...
remote: Enumerating objects: 659, done.
remote: Counting objects: 100% (659/659), done.
remote: Compressing objects: 100% (598/598), done.
remote: Total 659 (delta 40), reused 656 (delta 40), pack-reused 0
Receiving objects: 100% (659/659), 4.32 MiB | 9.77 MiB/s, done.
Resolving deltas: 100% (40/40), done.
[email protected] MINGW64 /e/workspace-python/test
$ ^C
[email protected] MINGW64 /e/workspace-python/test
使用pycharm打開此項目即可
Window下Git安裝使用
Git安裝
下載下傳Git,連結如下:https://git-scm.com/download/win
下載下傳完畢,打開安裝,按照安裝流程一步一步執行,選擇預設操作執行,直至該安裝完成。
gitee托管項目代碼
- 配置Git
打開Git Bash應用,界面顯示如下圖所示。
- 先輸入ssh-keygen –t rsa –C “郵箱位址”,注意ssh-keygen之間是沒有空格的,其他的之間是有空格的。
- 回車之後,會出現一行,讓你輸入一個儲存密鑰的地方,括号裡面是它預設的位置,這裡會讓你輸入幾次内容,都不用輸入,直接回車就可以了,可以看到如圖的效果。
- 回車之後,這樣密鑰就生成了,可以打開id_rsa.pub(上面一步可以看出建立的路徑)來檢視,裡面的所有内容就是這個密鑰,一會需要使用的時候,就直接全選複制就可以了。用記事本打開。
- 登入https://gitee.com/(預設你已經注冊了Gitee賬号)
- 驗證一下是否設定成功,在git bash下輸入如下指令,流程圖如下圖所示:
- 現在配置一下使用者名和郵箱:
git config --global user.name “使用者名”
git config --global user.email “郵箱”
ssh -T [email protected]
- 在gitee建立倉庫"sample.python",之後在gitbash中切換到自己本地代碼檔案目錄,配置倉庫
mkdir sample.python
cd sample.python
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin https://gitee.com/xiaolaifeng/sample.python.git
git push -u origin master
執行結果如圖
送出本地項目到Gitee
使用pycharm送出本地項目 (預設已經安裝以上步驟配置好ssh)
- 打開pycharm,點選右上角push按鈕