
Git Push, Clone and Login with a GitHub Personal Access Token (PAT)
Published · Updated
Short answer. GitHub stopped accepting account passwords for Git operations on 13 August 2021. Generate a Personal Access Token, then run your git push, git clone or git pull over HTTPS as usual: when Git asks for a password, paste the token. Let a credential helper remember it so you are not asked every time — see the FAQ below for which one to use.
See also: Introduction to Git and GitHub.
Introduction
So far, you’ve learned the basics of Git and GitHub. But how do you actually connect your local project to GitHub? That’s where Personal Access Tokens (PATs) come in.
GitHub has deprecated password authentication for Git operations, and now recommends using PAT tokens for secure access. In this blog, we’ll walk through the entire process of pushing a new project from your computer to GitHub — step by step.
Step 1: Configure Git (only once per computer)
Before pushing anything, you need to tell Git who you are. Run these commands in your terminal:
git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"
This sets up your identity. How Git remembers your token is covered in the FAQ at the end.
Step 2: Create a Spring Boot project
For this example, let’s create a demo project using Spring Initializr:
-
Go to https://start.spring.io/
-
Select:
- Project: Maven
- Language: Java
- Spring Boot: latest stable
- Group:
com.example - Artifact:
demo - (Optional) Add Spring Web dependency
-
Click Generate Project → a
.zipfile will download. -
Extract the project and open it in your IDE (IntelliJ IDEA or VS Code).
Step 3: Create an empty GitHub repository
Next, let’s set up a remote repository on GitHub:
- Log in to https://github.com.
- Click New Repository.
- Enter repo name →
spring-demo. - Keep the repository empty (don’t add README, .gitignore, or license).
- Click Create Repository.
Step 4: Generate a PAT (Personal Access Token)
Now we need a PAT to authenticate securely. GitHub offers two kinds: fine-grained tokens, which GitHub recommends whenever possible because each one is limited to chosen repositories and permissions, and classic tokens, which still cover a few cases fine-grained tokens do not (for example, contributing to a repository you were added to as an outside collaborator). This walkthrough uses a classic token because it works for every beginner case; see the FAQ for the fine-grained route.
-
Go to GitHub Settings → Developer Settings → Personal access tokens.
-
Click Tokens (classic) → Generate new token (classic).
-
Fill in details:
- Name:
spring-project-token - Expiration: 30 days (or as needed)
- Permissions: repo
- Name:
-
Click Generate token.
-
Copy the token (e.g.,
ghp_abc123XYZ...) and save it somewhere safe.
Step 5: Connect local project to GitHub
Open your terminal inside the Spring project folder and run:
git init
git remote add origin https://github.com/your-username/spring-demo.git
git add .
git commit -m "Initial Spring Boot project"
git branch -M main
git push -u origin main
Step 6: Authenticate with GitHub
When you run the push command:
- Git will ask for username → enter your GitHub username.
- Git will ask for password → paste your PAT token.
Step 7: Verify on GitHub
Finally, go to your repository on GitHub. You should now see your Spring Boot project uploaded successfully
Conclusion
That’s it! You’ve just connected your local Git project to GitHub using a Personal Access Token.
- Git is now configured on your machine.
- Your project is securely stored in GitHub.
- You’re ready to collaborate with others.
This process is a one-time setup per project — once done, future pushes will be much simpler.
FAQ: git push, clone and login with a PAT
How do I git push with a PAT?
Use an HTTPS remote (https://github.com/USERNAME/REPO.git) and run git push. When Git prompts for a username, enter your GitHub username; when it prompts for a password, paste the token. GitHub ignores the username for authentication — the token is what logs you in — but leaving the username empty makes the request fail.
How do I git clone with a PAT?
The same way: git clone https://github.com/USERNAME/REPO.git, then username plus token at the prompts. A public repository clones without any credentials; the prompt appears for a private one, or the first time you push.
How do I “log in” to Git with a PAT?
Git has no separate login command. You authenticate the first time an HTTPS operation needs it, and a credential helper stores the result. The simplest supported routes, per GitHub’s guide to caching credentials, are:
- GitHub CLI: run
gh auth login, choose HTTPS, and answer yes to authenticating Git with your GitHub credentials. - Git Credential Manager: bundled with Git for Windows; on macOS install it with Homebrew. It stores credentials in the system keychain or credential manager.
Is git config --global credential.helper store safe?
It works, but Git’s own documentation warns that this helper stores credentials unencrypted on disk, protected only by file permissions, in ~/.git-credentials. Anyone who can read that file can use your token. Prefer the GitHub CLI or Git Credential Manager above. If you already ran the store command, delete the token on GitHub, create a new one and switch helpers.
Should I put the token in the remote URL?
No. A URL such as https://TOKEN@github.com/... is saved in plain text in the repository’s .git/config and shows up in shell history and logs. Use the password prompt and a credential helper instead.
Git never asks for my token — it just fails
Your old password is probably cached. On macOS, update the GitHub entry in Keychain Access; on Windows, remove it from Credential Manager. The next push prompts again.
My remote starts with git@github.com: — does a PAT work?
No. Tokens work only for HTTPS. That remote uses SSH, which authenticates with an SSH key instead. Either set up a key, or switch the remote to HTTPS with git remote set-url origin https://github.com/USERNAME/REPO.git.
Fine-grained or classic token?
Use a fine-grained token when you can: choose the account that owns the repository as the resource owner, select only the repositories you need, and give it Contents: Read and write to push. Use a classic token with the repo scope when a fine-grained one cannot reach the repository — GitHub’s personal access token documentation lists those gaps.
What happens when the token expires?
Pushes start failing with an authentication error. Generate a new token, then push again and paste it when prompted — or, if the old token is cached, clear it first as described above. Pick an expiry that matches the project instead of choosing no expiry at all.
Next Steps
Once pushes work, protect the branch you push to: GitHub branch protection rules covers reviews and required checks. Pushing to client repositories with the right credentials, and nothing more, is everyday work in the Forward-Deployed Engineer program.