Post

Git Authentication: Common Mistakes and How to Fix Them

Git Authentication: Common Mistakes and How to Fix Them

Overview

This post documents real Git authentication mistakes I made and how I fixed them. If you’re new to Git, you’ll probably hit these same walls. Learn from my errors!

The Scenario

I was trying to push changes to my GitHub repository after making some updates. Simple task, right? Here’s what happened…

Mistake #1: Forgetting the -m Flag

What I typed:

1
git commit "Updating the folder - Added info to readme.md"

Error:

1
error: pathspec 'Updating the folder - Added info to readme.md' did not match any file(s) known to git

Why it failed: Git thought my message was a file path, not a commit message!

The fix:

1
2
3
git commit -m "Updating the folder - Added info to readme.md"
#          ^^
#          This flag is REQUIRED!

Lesson: The -m flag tells Git “this is my message”. Without it, Git interprets everything as filenames.


Mistake #2: Mismatched Quotes

What I typed:

1
git commit -m "Updating the folder - Added info to readme.md'

What happened:

1
dquote>

Why: I started with a double quote " but ended with a single quote '. The terminal kept waiting for the closing ".

The fix:

1
2
3
4
5
6
7
# Press Ctrl+C to cancel
^C

# Use matching quotes
git commit -m "Updating the folder - Added info to readme.md"
#           ^                                                ^
#           Both double quotes!

Lesson: Always match your quotes. "..." or '...', never mix them.


Mistake #3: Trying git login

What I typed:

1
2
3
4
git push
Username for 'https://github.com': ^C

git login

Error:

1
2
3
4
git: 'login' is not a git command. See 'git --help'.

The most similar command is
        column

Why it failed: There’s no git login command! Git doesn’t work like that.

The reality: Git authentication happens:

  1. During push/pull/clone operations
  2. Via credentials (username + token)
  3. Or via SSH keys

Mistake #4: Committing as Wrong Identity

What happened:

1
2
3
4
5
git commit -m "My message"

Committer: kali <kali@kali>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.

The problem: Git used my system username kali instead of my GitHub identity. This means:

  • Commits won’t link to my GitHub profile
  • No green contribution squares
  • Looks unprofessional

The fix:

1
2
3
4
5
6
7
# Set your real identity
git config --global user.name "davidtkeane"
git config --global user.email "your@github-email.com"

# Fix the last commit
git commit --amend --reset-author --no-edit
git push --force

Mistake #5: Entering Password Instead of Token

What I thought:

1
2
git push
Password: <my GitHub password>

Error:

1
2
3
remote: Support for password authentication was removed on August 13, 2021.
remote: Please use a personal access token instead.
fatal: Authentication failed for 'https://github.com/...'

Why: GitHub disabled password authentication in 2021 for security reasons.

The fix:

  1. Generate a Personal Access Token (PAT)
  2. Use the token as your “password”

The Correct Git Push Flow

Here’s what finally worked:

Step 1: Set Up Identity (One Time)

1
2
git config --global user.name "davidtkeane"
git config --global user.email "your@email.com"

Step 2: Store Credentials (One Time)

1
git config --global credential.helper store

Step 3: Generate GitHub Token

  1. Go to GitHub.com → Settings
  2. Developer Settings → Personal Access Tokens → Tokens (classic)
  3. Generate new token
  4. Select scopes: repo (full control)
  5. Copy the token (starts with ghp_...)

Step 4: Push and Authenticate

1
2
3
git push
Username: davidtkeane
Password: ghp_your_token_here  # Paste token, not password!

Step 5: Verify Success

1
2
3
4
5
6
7
8
9
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 2 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 305 bytes | 305.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/davidtkeane/MorseBash.git
   6a821db..a7adf42  main -> main

That’s it! The token is now saved. Future pushes are automatic!


Quick Reference: What Goes Where

TaskCommand
Set namegit config --global user.name "name"
Set emailgit config --global user.email "email"
Save credentialsgit config --global credential.helper store
View configgit config --global --list
See saved credentialscat ~/.git-credentials

Error Messages Decoded

“pathspec did not match any file(s)”

Cause: Missing -m flag or typo in filename Fix: git commit -m "message"

“dquote>” or “quote>”

Cause: Unclosed quote Fix: Press Ctrl+C, use matching quotes

“not a git command”

Cause: Typo or command doesn’t exist Fix: Check git --help or Google it

“configured automatically based on username”

Cause: Identity not set Fix: git config --global user.name/email

“Support for password authentication was removed”

Cause: Using password instead of token Fix: Generate Personal Access Token


Prevention Tips

1. Set Up Once, Forget Forever

1
2
3
4
5
# Run these ONCE after installing Git
git config --global user.name "your-username"
git config --global user.email "your@email.com"
git config --global credential.helper store
git config --global init.defaultBranch main

2. Use SSH Instead of HTTPS

1
2
3
4
5
6
7
8
9
10
11
# Generate SSH key
ssh-keygen -t ed25519 -C "your@email.com"

# Add to GitHub (Settings → SSH Keys)
cat ~/.ssh/id_ed25519.pub

# Change remote to SSH
git remote set-url origin git@github.com:user/repo.git

# Never enter credentials again!
git push  # Just works

3. Create Aliases for Safety

1
2
3
4
5
# In ~/.zshrc or ~/.bashrc
alias gp='git push'
alias gc='git commit -m'
alias gs='git status'
alias ga='git add'

4. Check Before Commit

1
2
3
git status        # See what's staged
git diff --staged # See actual changes
git commit -m "..." # Then commit

My Final Setup

After all the mistakes, here’s my working configuration:

1
2
3
4
5
6
> git config --global --list

user.name=davidtkeane
user.email=my@email.com
credential.helper=store
init.defaultbranch=main

And my workflow:

1
2
3
4
git add .
git commit -m "Clear descriptive message"
git push
# No prompts, no errors, just works!

Key Takeaways

  1. -m is not optional - You must use it for inline commit messages
  2. Match your quotes - "..." or '...', never mix
  3. There’s no git login - Authentication happens during operations
  4. Tokens, not passwords - GitHub requires Personal Access Tokens
  5. Set up identity first - Avoid the “kali kali@kali” warnings
  6. Store credentials once - Never enter token again

Resources


Making mistakes is the best way to learn. Now I’ll never forget the -m flag or mismatched quotes again. And neither will you!

Remember: Everyone struggles with Git authentication at first. Once you set it up correctly, it just works forever.

This post is licensed under CC BY 4.0 by the author.