git clone https://github.com/git/git(不建議生產環境編譯安裝)。https://your_username@bitbucket.org/your_username/repo_name.gitgit config --global user.name "your_username"
git config --global user.email "your_email@domain.com"
git config --global push.default simple # 推送預設行為:僅推送當前分支至同名上游
cd ~/workspace/my_project
git init
git add . # 暫存所有檔案
git commit -m "initial commit" # 首次提交
git status # 查看狀態
git checkout -b new_feature # 建立並切換
# 或分兩步
git branch new_feature
git checkout new_feature
git branch # 本地分支
git branch -a # 含遠端分支
git add .
git commit -m "adds new feature"
git checkout master
git merge new_feature
git add .
git commit -m "discard feature"
git checkout master
# 分支內容已回到建立前狀態
git branch -d new_feature # 已合併才能刪
git branch -D new_feature # 強制刪除未合併分支
git log # 查看提交歷史
git checkout # 暫時切換到舊版本(分離 HEAD 狀態)
git checkout -b old_version # 基於舊版本建新分支
git remote add origin https://your_username@bitbucket.org/your_username/repo_name.git
git push origin master
cd ~/workspace
git clone https://your_username@bitbucket.org/your_username/repo_name.git
cd repo_name
git pull origin master
git config --global alias.c 'commit -m'
git config --global alias.co 'checkout'
git config --global alias.br 'branch'
git config --global alias.st 'status'
git config --global alias.lg "log --oneline --graph --all"
掌握 Git 核心工作流與分支策略,能讓個人或團隊開發更有序、可追溯。建議養成「小步提交、頻繁推送、善用分支」的習慣,並熟悉 rebase、cherry-pick、stash 等進階指令應對複雜場景。