官網 github.com 註冊,驗證郵箱。
# CentOS/RHELyum install git git-gui# Ubuntu/Debianapt update && apt install git# 源碼編譯 (最新版)wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.45.0.tar.gz./configure --prefix=/usr/local/git && make && make install ssh-keygen -t ed25519 -C "your_email@example.com" # 推薦 ed25519# 連續回車 (無密碼) 或設置密碼短語cat ~/.ssh/id_ed25519.pub # 複製內容 GitHub → Settings → SSH and GPG keys → New SSH key → 粘貼公鑰。
ssh -T git@github.com# Hi username! You've successfully authenticated... git config --global user.name "Your Real Name"git config --global user.email "your_email@example.com"git config --global init.defaultBranch main # Git 2.28+git config --global core.editor vim mkdir my-project && cd my-projectgit init # 初始化 .gitgit add . # 暫存所有文件git commit -m "Initial commit"# 在 GitHub 網頁創建同名倉庫 (不勾選 README/License)git remote add origin git@github.com:username/my-project.gitgit push -u origin main # 首次推送並建立追蹤關系 | 錯誤 | 原因 | 修復 |
|---|---|---|
Permission denied (publickey) | SSH 金鑰未上傳/不匹配/agent 未載入 | ssh-add ~/.ssh/id_ed25519、檢查 ~/.ssh/config Host github.com IdentityFile |
403 / fatal: HTTP request failed | 使用 HTTPS URL 但無 Token/密碼 | 改用 SSH URL:git remote set-url origin git@github.com:user/repo.git |
reject non-fast-forward | 遠程有本地無的提交 | git pull --rebase origin main 後再 push |
LF will be replaced by CRLF | 換行符警告 | git config --global core.autocrlf input (Linux/macOS) |
git status # 查看狀態git diff # 工作區 vs 暫存區git diff --staged # 暫存區 vs 倉庫git add -p # 交互式暫存 (塊級)git commit -v # 編輯器查看 diff 後提交git log --oneline --graph --all # 圖形化歷史git stash # 暫存未完成工作git stash pop # 恢復 # ~/.ssh/configHost github.com-work HostName github.com User git IdentityFile ~/.ssh/id_ed25519_workHost github.com-personal HostName github.com User git IdentityFile ~/.ssh/id_ed25519_personal# 使用git remote set-url origin git@github.com-work:company/project.git
Linux 忘記 root 密碼?單用戶模式清除密碼 3 步驟搞定
Linux 內核 3.15-rc7 發布:Linus Torvalds 預告正式版即將到來
Linux root 密碼遺忘?三種單用戶模式重置密碼實戰教學
Vim 進階操作大全:宏、標籤、分割視窗、暫存器、書籤、可視模式完全指南
RedHat 6.4 本地 yum 與 FTP yum 源雙模式配置實戰:掛載 ISO、建立 .repo、vsftpd 匿名存取、驗證安裝
Linux 網卡 IP 地址配置三大方式:ifconfig 臨時、setup 圖形、配置文件持久化