560 字
3 分鐘
瀏覽次數
Git Initial Project Upload and Commit Email Correction Process
2026-10-02

Conclusion#

When uploading a Git project for the first time, set the correct user information beforehand. If you discover an incorrect Commit Email after pushing, you can use git commit --amend --reset-author to correct the most recent Commit, then safely force update the remote.

When to Use This#

  • First-time upload of a local project to GitHub
  • Discovering incorrect author name or email settings after a commit
  • GitHub Contribution not correctly linked to the account
  • Only needing to correct the author information of the “most recent commit”

Step-by-Step Process#

1. Initialize Git Project#

Initialize Git in your project directory, add all files, and set your GitHub Repository as the remote source.

Terminal window
git init
git add .
git remote add origin https://github.com/user-name/project-name.git
git branch -M main

git branch -M main renames the current branch to main to prevent discrepancies between local and remote default branch names.

2. Configure Commit Author Information and Upload#

Before the first commit, ensure user.name and user.email are correct; otherwise, the commit will record incorrect author information.

Terminal window
# 設定目前 Repository 的 Git 作者資訊
git config user.name "user-name"
git config user.email "user-email"
# HTTPS Credential 依完整 Repository 路徑區分
git config credential.useHttpPath true
# 建立第一次 Commit
git commit -m "Initial commit"
# 上傳到 GitHub
git push -u origin main

If you want the settings to apply to all repositories, add --global; otherwise, omit it to affect only the current project.

Terminal window
git config --global user.name "user-name"
git config --global user.email "user-email"

3. Correcting an Already Committed Email#

If you’ve already committed, or even pushed, and then discover an incorrect author email, first change your Git settings to the correct information, then recreate the author information for the most recent commit.

Terminal window
# 先設定正確作者資訊
git config user.name "user-name"
git config user.email "user-email"
# 使用目前設定重新建立最近一次 Commit 作者資訊
git commit --amend --reset-author --no-edit
# 確認修改結果
git log -1 --format="%an <%ae>"
# 更新遠端 Commit
git push --force-with-lease origin main
  • -no-edit preserves the original Commit Message; -reset-author rewrites the author information using the current Git settings.

Additional Notes#

  • git commit --amend generates a new Commit Hash, so a pushed commit will require a force update to the remote.
  • Prioritize using -force-with-lease as it is safer than direct -force, reducing the risk of overwriting someone else’s remote updates.
  • The method above only corrects the “most recent commit”; if the incorrect email exists in multiple historical commits, you’ll need to rewrite Git History, which cannot be done with a single -amend.

Command / Example Summary#

Click to expand
Terminal window
# 初始化專案
git init
git add .
git remote add origin https://github.com/user-name/project-name.git
git branch -M main
# 設定作者
git config user.name "user-name"
git config user.email "user-email"
git config credential.useHttpPath true
# 第一次 Commit / Push
git commit -m "Initial commit"
git push -u origin main
# 修正最近一次 Commit 作者資訊
git commit --amend --reset-author --no-edit
# 確認 Author
git log -1 --format="%an <%ae>"
# 更新遠端
git push --force-with-lease origin main

Conclusion#

Confirming user.name and user.email before your first push can save you the trouble of modifying Commit History later. If you do push with incorrect information, amend + force-with-lease is the most straightforward way to correct the most recent commit.

Git Initial Project Upload and Commit Email Correction Process
https://joyceowo.github.io/posts/en/3eda78ea09fa809cb3bfdf649a817149/
作者
JoyceOwO
發佈於
2026-10-02
許可協議
CC BY-NC-SA 4.0