Git Daily Workflow Git 日常工作流程 Git 日常工作流程 Git Daily Workflow

Prerequisites: 前置條件: 前置条件: Mga Kinakailangan: Before using Git with Gitea, make sure you have completed the SSH Key Setup guide. You also need Git installed on your computer. 使用 Git 搭配 Gitea 之前,請先完成 SSH 金鑰設定指南。你也需要在電腦上安裝 Git。 使用 Git 搭配 Gitea 之前,请先完成 SSH 密钥设置指南。你也需要在电脑上安装 Git。 Bago gumamit ng Git sa Gitea, siguraduhing natapos mo na ang SSH Key Setup guide. Kailangan mo rin ng Git na naka-install sa iyong computer.

Check that Git is installed: 確認 Git 已安裝: 确认 Git 已安装: I-check na naka-install ang Git:

$ git --version
git version 2.x.x

Configure your name and email. These will appear on every commit you make: 設定你的名字和電郵。這些資訊會出現在你的每個 commit 中: 设置你的名字和邮箱。这些信息会出现在你的每个 commit 中: I-configure ang iyong pangalan at email. Lalabas ang mga ito sa bawat commit mo:

$ git config --global user.name "Your Name"
$ git config --global user.email "your.name@datawords.asia"
Tip: 提示: 提示: Tip: Use the same email address that you used for your Gitea account so that commits are linked to your profile. 請使用和 Gitea 帳號相同的電郵地址,這樣 commit 才會連結到你的個人頁面。 请使用和 Gitea 账号相同的邮箱地址,这样 commit 才会链接到你的个人页面。 Gamitin ang parehong email address na ginamit mo sa iyong Gitea account para ma-link ang mga commit sa iyong profile.

Verify your configuration: 確認你的設定: 确认你的设置: I-verify ang iyong configuration:

$ git config --global user.name
Your Name
$ git config --global user.email
your.name@datawords.asia

Cloning downloads a copy of a repository from Gitea to your computer. You only need to do this once per project. Clone 是從 Gitea 下載一份 repository 副本到你的電腦。每個專案只需要做一次。 Clone 是从 Gitea 下载一份仓库副本到你的电脑。每个项目只需要做一次。 Ang Clone ay nagda-download ng kopya ng repository mula sa Gitea papunta sa iyong computer. Isang beses lang ito kailangan gawin bawat project.

First, find the SSH clone URL on Gitea. Go to the repository page and click the SSH button to copy the URL: 首先,在 Gitea 找到 SSH clone URL。進入 repository 頁面,點擊 SSH 按鈕複製 URL: 首先,在 Gitea 找到 SSH clone URL。进入仓库页面,点击 SSH 按钮复制 URL: Una, hanapin ang SSH clone URL sa Gitea. Pumunta sa repository page at i-click ang SSH button para kopyahin ang URL:

Gitea HTTPS SSH git@git-ssh.datawords.hk:MyOrg/my-project.git Copy Select SSH 選擇 SSH 选择 SSH Piliin ang SSH

Then run the clone command in your terminal: 然後在終端機執行 clone 指令: 然后在终端执行 clone 命令: Pagkatapos, i-run ang clone command sa iyong terminal:

$ git clone git@git-ssh.datawords.hk:MyOrg/my-project.git
Cloning into 'my-project'...
$ cd my-project
Tip: 提示: 提示: Tip: Always use the SSH URL (starting with git@), not HTTPS. SSH uses the key you set up earlier so you don't need to enter a password every time. 請一律使用 SSH URL(以 git@ 開頭),而非 HTTPS。SSH 會使用你之前設定的金鑰,不需要每次輸入密碼。 请一律使用 SSH URL(以 git@ 开头),而非 HTTPS。SSH 会使用你之前设置的密钥,不需要每次输入密码。 Laging gumamit ng SSH URL (nagsisimula sa git@), hindi HTTPS. Gagamitin ng SSH ang key na na-setup mo kanina para hindi na kailangan ng password.

A branch is a separate line of development. Always create a new branch for your work instead of committing directly to develop. 分支(Branch)是一條獨立的開發線。請永遠為你的工作建立新分支,而不是直接在 develop 上提交。 分支(Branch)是一条独立的开发线。请永远为你的工作创建新分支,而不是直接在 develop 上提交。 Ang branch ay isang hiwalay na linya ng development. Laging gumawa ng bagong branch para sa iyong trabaho sa halip na mag-commit nang diretso sa develop.

develop feature/my-task merge 合併 合并 merge

Make sure you're on the latest develop branch first, then create a new branch: 先確保你在最新的 develop 分支,然後建立新分支: 先确保你在最新的 develop 分支,然后创建新分支: Siguraduhing nasa pinakabagong develop branch ka muna, pagkatapos gumawa ng bagong branch:

$ git checkout develop
$ git pull
$ git checkout -b feature/my-task

Common branch naming patterns: 常見的分支命名方式: 常见的分支命名方式: Mga karaniwang paraan ng pagpangalan ng branch:

  • feature/add-login-pagenew feature 新功能 新功能 bagong feature
  • fix/broken-linkbug fix 修復 bug 修复 bug pag-aayos ng bug
  • docs/update-readmedocumentation change 文件修改 文档修改 pagbabago sa documentation

To check which branch you're currently on: 查看你目前在哪個分支: 查看你目前在哪个分支: Para i-check kung anong branch ka ngayon:

$ git branch
  develop
* feature/my-task

To switch between existing branches: 切換到已有的分支: 切换到已有的分支: Para lumipat sa ibang existing branch:

$ git checkout develop         # switch to develop
$ git checkout feature/my-task  # switch back

A commit saves a snapshot of your changes. Think of it like a checkpoint you can always go back to. Commit 會儲存你的修改快照,就像一個隨時可以回到的存檔點。 Commit 会保存你的修改快照,就像一个随时可以回到的存档点。 Ang commit ay nagse-save ng snapshot ng iyong mga pagbabago. Isipin mo itong checkpoint na pwede mong balikan anumang oras.

Step 1: Check what files you've changed: 步驟一:檢查你改了哪些檔案: 步骤一:检查你改了哪些文件: Step 1: I-check kung anong mga file ang nabago mo:

$ git status
On branch feature/my-task
Changes not staged for commit:
  modified:   src/index.html
Untracked files:
  src/new-file.js

Step 2: Stage the files you want to include in the commit: 步驟二:將要提交的檔案加入暫存區: 步骤二:将要提交的文件加入暂存区: Step 2: I-stage ang mga file na gusto mong isama sa commit:

$ git add src/index.html src/new-file.js  # add specific files
Tip: 提示: 提示: Tip: To stage all changed files at once, use git add . — but review with git status first to make sure you're not including unwanted files. 要一次加入所有改動的檔案,可以用 git add .,但請先用 git status 確認不會加入不需要的檔案。 要一次加入所有改动的文件,可以用 git add .,但请先用 git status 确认不会加入不需要的文件。 Para i-stage lahat ng nabagong file nang sabay-sabay, gamitin ang git add . — pero i-review muna sa git status para hindi makapasok ang hindi kailangan.

Step 3: Commit with a descriptive message: 步驟三:用描述性訊息來 commit: 步骤三:用描述性消息来 commit: Step 3: Mag-commit na may malinaw na message:

$ git commit -m "feat: add user login page"

Good commit messages describe what you changed and why: 好的 commit message 要描述你改了什麼為什麼 好的 commit message 要描述你改了什么为什么 Ang magandang commit message ay naglalarawan kung ano ang binago at bakit:

  • fix: prevent crash when user email is empty
  • feat: add search filter for project list
  • update
  • fix stuff
Important: 重要: 重要: Mahalaga: Never commit sensitive files like .env, passwords, or API keys. Add them to .gitignore to prevent accidental commits. 絕對不要 commit 敏感檔案,如 .env、密碼或 API 金鑰。請將它們加入 .gitignore 來防止意外提交。 绝对不要 commit 敏感文件,如 .env、密码或 API 密钥。请将它们加入 .gitignore 来防止意外提交。 Huwag kailanman i-commit ang mga sensitive file tulad ng .env, password, o API key. Idagdag ang mga ito sa .gitignore para maiwasan ang hindi sinasadyang commit.

Push uploads your commits from your computer to Gitea. Pull downloads the latest changes from Gitea to your computer. Push 將你的 commit 從電腦上傳到 Gitea。Pull 從 Gitea 下載最新的改動到你的電腦。 Push 将你的 commit 从电脑上传到 Gitea。Pull 从 Gitea 下载最新的改动到你的电脑。 Ang Push ay nag-a-upload ng iyong mga commit mula sa computer patungong Gitea. Ang Pull ay nagda-download ng pinakabagong mga pagbabago mula sa Gitea papunta sa iyong computer.

Your Computer你的電腦你的电脑Iyong Computer Local Gitea Remote git push git pull

Push

After committing, push your branch to Gitea. The first time you push a new branch, use -u to set up tracking: Commit 之後,將你的分支推送到 Gitea。第一次推送新分支時,用 -u 建立追蹤關係: Commit 之后,将你的分支推送到 Gitea。第一次推送新分支时,用 -u 建立追踪关系: Pagkatapos mag-commit, i-push ang iyong branch sa Gitea. Sa unang beses na mag-push ng bagong branch, gamitin ang -u para i-setup ang tracking:

$ git push -u origin feature/my-task  # first push

After that, just git push is enough: 之後只需要 git push 就可以了: 之后只需要 git push 就可以了: Pagkatapos noon, git push lang ang kailangan:

$ git push

Pull

Before starting work each day, pull the latest changes to stay in sync: 每天開始工作前,先拉取最新的改動來保持同步: 每天开始工作前,先拉取最新的改动来保持同步: Bago magsimulang magtrabaho araw-araw, i-pull ang pinakabagong mga pagbabago para maka-sync:

$ git pull

To update your feature branch with the latest changes from develop: 要將 develop 的最新改動同步到你的功能分支: 要将 develop 的最新改动同步到你的功能分支: Para i-update ang iyong feature branch gamit ang pinakabagong mga pagbabago mula sa develop:

$ git checkout feature/my-task
$ git pull origin develop
Tip: 提示: 提示: Tip: If you see a merge conflict, don't panic. Git will mark the conflicting lines in the file. Open the file, choose which version to keep, remove the conflict markers (<<<<<<<, =======, >>>>>>>), then commit the result. 如果你看到合併衝突,不用緊張。Git 會在檔案中標記衝突的行。打開檔案,選擇要保留的版本,刪除衝突標記(<<<<<<<=======>>>>>>>),然後 commit 結果。 如果你看到合并冲突,不用紧张。Git 会在文件中标记冲突的行。打开文件,选择要保留的版本,删除冲突标记(<<<<<<<=======>>>>>>>),然后 commit 结果。 Kung makakita ka ng merge conflict, huwag mag-panic. Mma-mark ng Git ang mga linya na may conflict sa file. Buksan ang file, piliin kung aling version ang itatabi, alisin ang conflict markers (<<<<<<<, =======, >>>>>>>), pagkatapos i-commit ang resulta.

Quick reference of the most common Git commands: 最常用的 Git 指令速查表: 最常用的 Git 命令速查表: Mabilis na reference ng pinaka-karaniwang Git commands:

Command 指令 命令 Command What it does 作用 作用 Ano ang ginagawa
git clone <url> Download a repository 下載一個 repository 下载一个仓库 I-download ang repository
git status See what files have changed 查看哪些檔案有改動 查看哪些文件有改动 Tingnan kung anong mga file ang nabago
git add <file> Stage a file for commit 將檔案加入暫存區 将文件加入暂存区 I-stage ang file para sa commit
git commit -m "msg" Save staged changes with a message 儲存暫存區的改動並附上訊息 保存暂存区的改动并附上消息 I-save ang mga staged na pagbabago na may message
git push Upload commits to Gitea 上傳 commit 到 Gitea 上传 commit 到 Gitea I-upload ang mga commit sa Gitea
git pull Download latest changes from Gitea 從 Gitea 下載最新改動 从 Gitea 下载最新改动 I-download ang pinakabagong mga pagbabago mula sa Gitea
git branch List all local branches 列出所有本地分支 列出所有本地分支 Ilista lahat ng local branches
git checkout <branch> Switch to a branch 切換到某個分支 切换到某个分支 Lumipat sa isang branch
git checkout -b <name> Create and switch to a new branch 建立新分支並切換過去 创建新分支并切换过去 Gumawa at lumipat sa bagong branch
git log --oneline Show commit history (short) 顯示 commit 歷史(簡短) 显示 commit 历史(简短) Ipakita ang commit history (maikli)
git diff Show unstaged changes 顯示未暫存的改動 显示未暂存的改动 Ipakita ang mga hindi pa na-stage na pagbabago

You're ready! 你準備好了! 你准备好了! Handa ka na!

These commands cover 90% of daily Git usage. Next, learn how to create Pull Requests to get your code reviewed and merged. 這些指令涵蓋了日常 90% 的 Git 使用。接下來可以學習如何建立 Pull Request 來讓你的程式碼被審核並合併。 这些命令涵盖了日常 90% 的 Git 使用。接下来可以学习如何创建 Pull Request 来让你的代码被审核并合并。 Sakop ng mga command na ito ang 90% ng araw-araw na Git usage. Susunod, matutunan kung paano gumawa ng Pull Request para ma-review at ma-merge ang iyong code.