Preface
Git workflow is divided into two situations.
- New repository/project. Need to initialise a git repository and push it to the remote repository.
- Exist repository for further development. The remote repository is already there, only need to working on it.
New Repo
Setup credentials (email & username) in Git. Tell git who is the author of the code.
Git uses a username to associate commits with an identity. The Git username is not the same as your GitHub username (of course you can make it the same).
The name you set will be visible in any future commits you push to GitHub from the command line. If you want to keep your real name private, use any text as your Git username.
Changing the name associated with your Git commits using
git config
will only affect future commits and will not change the name used for past commits.The error happens when I try to commit without setup credentials.
Error Message
1
2
3
4
5
6
7
8
9
10
11
12
13Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'andy@Andy-iMacPro.(none)')This is because we did not specify the code’s author or who is currently operating this commit.
This can be solved by setting up your credentials (email and username).
Solution
1
2
3
4
5
6
7
8
9
10
11
12# --global: Setting your Git email and username for every repository on your computer
# If you want to setup locally. Eg. Only current repo, just remove --global
# Set a Git email syntax
git config --global user.email "[email protected] Your-Email-Address"
# Eg.
git config --global user.email "[email protected]"
# Set a Git username syntax
git config --global user.name "Your Name or Author Name"
# Eg.
git config --global user.name "Andy"If you do not want to set for every git repo in your computer, just remove
--global
so it can set up credentials for a single repo.Validation
1
2
3
4
5
6
7
8
9# Validate current git user email address
git config --global user.email
# Sample output
[email protected]
# Validate current git username
git config --global user.name
# Sample output
AndyInitialise an empty git repository
1
2
3# Eg. TestRepo
cd /Andy/Repo/TestRepo
git initWrite code or make any changes
Add files for commit
1
2
3
4
5# Add all files in current directory
git add .
# Or add a specific file in the current directory for commit. Eg. README.md
git add README.mdCommit with a commit message
1
git commit -m "Commit message related to your current commit"
Create a branch called “main”
1
git branch -M main
Add remote git repository endpoint
1
git remote add origin https://github.com/JinchuanL/TestRepo.git
Push to the remote repository
1
git push -u origin main
Exist repo for development
1 | # Get the latest update first |
Reference
About this Post
This post is written by Andy, licensed under CC BY-NC 4.0.