1. Generate a Personal Access Token (PAT) on GitHub:
Since GitHub has discontinued the use of account passwords for authentication to GitHub.com, you need to use a Personal Access Token (PAT) instead.
- Go to [GitHub Settings] https://github.com/settings/tokens
- Click on Generate new token
- Select the appropriate scopes or permissions (e.g., `repo` for full control of private repositories).
→ Click **Generate token** and copy the generated token.
2. Authenticate Git with the Personal Access Token:
You need to configure your Git clientto use the PAT for authentication.
You can do this by setting up a credential helper or by manually entering the token when prompted.
**Using a credential helper:**
- Install the Git Credential Manager if you haven't already. This can be done by running:
```sh
git config --global credential.helper manager
```
- When you push to GitHub, you'll be prompted for your username and password.
Use your GitHub username and the PAT as the password.
**Manually entering the token:**
- When you push, you will be asked for your username and password. Enter your GitHub username and use the PAT as the password.
3. **Perform the Push Again:**
Try the push command again:
```sh
git push -u origin main
```
Here are the steps for generating a PAT and configuring Git to use it:
### Step-by-Step Guide:
1. **Generate Personal Access Token:**
- Navigate to GitHub and log in.
- Go to **Settings** > **Developer settings** > **Personal access tokens**.
- Click **Generate new token**.
- Give your token a descriptive name, select the scopes you need, and click **Generate token**.
- Copy the token. You will not be able to see it again.
2. **Configure Git to Use the Token:**
**Option 1: Using Credential Manager**
```sh
git config --global credential.helper manager
```
**Option 2: Manually Entering the Token**
- When prompted for a username and password during a `git push` or `git pull`, enter your GitHub username and the PAT as the password.
### Example:
1. Generate the PAT from GitHub (make sure to copy it).
2. In your terminal, configure Git to use the credential helper:
```sh
git config --global credential.helper manager
```
3. When you push to GitHub, you'll see:
```sh
git push -u origin main
Username for 'https://github.com': <your_github_username>
Password for 'https://your_github_username@github.com': <your_pat>
```
4. After entering the credentials, Git should successfully push your changes.
By following these steps, you should be able to authenticate your local Git client with your GitHub repository and perform push and pull operations seamlessly.
Want to print your doc? This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (