Generate a new Authentication Token
1. Generate a New GitHub Personal Access Token (PAT)
Step 1: Go to GitHub Developer Settings
- Open GitHub in your browser and log in.
- Go to Settings (click your profile icon in the top right and select “Settings”).
- Scroll down and find Developer settings (on the left sidebar).
- Click Personal access tokens > Fine-grained tokens (recommended).
Step 2: Generate a New Token
- Click Generate new token (Fine-grained token).
- Set a note for the token (e.g., “Git CLI access”).
- Set an expiration date (or “No expiration” if you want it permanent).
- Under Permissions, select:
repo→ Read and Write (for full repo access).workflow→ Read and Write (if using GitHub Actions).
- Click Generate token.
{% note danger %} ⚠ Important: Copy the token immediately! You won’t be able to see it again. {% endnote %}
2. Use the Token for Authentication
Option 1: Use the Token for HTTPS Authentication
If you’re using HTTPS, update your Git credentials:
1$ git remote set-url origin https://<your-username>:<your-token>@github.com/<your-username>/<your-repo>.git
Or, when prompted during git push, enter:
- Username: your GitHub username
- Password: the generated token
Option 2: Cache Credentials to Avoid Repeated Login
To avoid re-entering credentials every time, enable Git credential caching:
For temporary cache (15 minutes default)
1$ git config --global credential.helper cache
For permanent storage (Linux)
1$ git config --global credential.helper store
Then push again and enter your token; Git will store it for future use.
Option 3: Use SSH Authentication (More Secure)
{% note primary %} Note: This method is highly recommended. {% endnote %}
For a permanent setup, switch to SSH authentication instead of HTTPS.
Check for existing SSH keys:
1$ ls ~/.ssh/id_rsa.pubIf the file doesn’t exist, generate a new SSH key:
1$ ssh-keygen -t rsa -b 4096 -C "your-email@example.com"Press Enter to accept the default file location.
Add the SSH key to GitHub:
1$ cat ~/.ssh/id_rsa.pub- Copy the output.
- Go to GitHub > Settings > SSH and GPG keys.
- Click New SSH key, paste the key, and save.
Test the SSH connection:
1$ ssh -T git@github.comIf successful, update Git remote:
1$ git remote set-url origin git@github.com:<your-username>/<your-repo>.git
3. Pull a Repository from Remote
Supposing you have a remote repository, and you are using SSH authentication, then you can pull it with the following command:
1$ git clone git@github.com:<your-username>/<your-repo>.git
4. Initialize a New Repository
If the repository is not initialized, run:
1$ git init
2$ git remote add origin git@github.com:<your-username>/<your-repo>.git
Then add and commit your files:
1$ git add .
2$ git commit -m "Initial commit"
3$ git push -u origin main # Or replace 'main' with your default branch
5. Pushing Branch
After updating authentication, try pushing your branch again:
1$ git push origin <your-branch-name>
If using SSH:
1$ GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa" git push origin <your-branch-name>
Let me know if you need more help! 🚀
6. If the Repository Was Cloned and Lost Its Connection
Sometimes, if you cloned a repo but lost the remote connection, re-add it:
1$ git remote add origin git@github.com:<your-username>/<your-repo>.git
Then verify it:
1$ git remote -v
Git Clone Guide
Method 1: Clone Using HTTPS with a Personal Access Token (PAT)
Since GitHub no longer supports password authentication for Git operations, you must use a Personal Access Token (PAT).
Step 1: Generate a Personal Access Token
- Go to GitHub → Settings → Developer settings → Fine-grained tokens.
- Click “Generate new token” → “Fine-grained token”.
- Set expiration date (or “No expiration” for permanent access).
- Under Repository Access, select your private repo.
- Under Permissions, select:
Contents→ Read and Write (to pull & push).Metadata→ Read (to access repo metadata).
- Click Generate token and copy the token.
Step 2: Clone Using Your Token
Use the following command:
1$ git clone https://<your-username>:<your-token>@github.com/<your-username>/<your-repo>.git
For example:
1$ git clone https://your-username:ghp_yourPAT1234@github.com/your-username/private-repo.git
💡 Note: If your token contains special characters (@, $, !), wrap it in single quotes.
Step 3: Avoid Re-entering Credentials
To prevent Git from asking for your token every time, enable credential caching:
1$ git config --global credential.helper store
Then, when prompted, enter your token once, and it will be stored.
Method 2: Clone Using SSH (Recommended for Permanent Setup)
This method is more secure and avoids entering your credentials repeatedly.
Step 1: Check for an Existing SSH Key
Run:
1$ ls ~/.ssh/id_rsa.pub
- If the file exists, you already have an SSH key. Skip to Step 3.
- If it does not exist, generate one.
Step 2: Generate a New SSH Key (If Needed)
Run:
1$ ssh-keygen -t rsa -b 4096 -C "your-email@example.com"
Press Enter for default file location (~/.ssh/id_rsa).
Then, add the key to your SSH agent:
1$ eval "$(ssh-agent -s)"
2$ ssh-add ~/.ssh/id_rsa
Step 3: Add the SSH Key to GitHub
- Copy your SSH key:
1$ cat ~/.ssh/id_rsa.pub - Go to GitHub → Settings → SSH and GPG keys.
- Click New SSH Key, paste the key, and save.
Step 4: Clone the Private Repo
Now, clone your repo using SSH:
1$ git clone git@github.com:<your-username>/<your-repo>.git
For example:
1$ git clone git@github.com:your-username/private-repo.git
Step 5: Test Your SSH Connection
Run:
1$ ssh -T git@github.com
If successful, you should see:
Hi <your-username>! You've successfully authenticated, but GitHub does not provide shell access.
Submodule Issues
If you don’t want dotfiles/.config/emacs to be a submodule but instead a normal folder inside your Git repository, follow these steps to remove the submodule and add it as a regular directory.
Step 1: Remove the Submodule Reference
Git tracks submodules differently from normal directories. To fully remove it, run:
1$ git submodule deinit -f dotfiles/.config/emacs
2$ rm -rf .git/modules/dotfiles/.config/emacs
3$ git rm -f dotfiles/.config/emacs
This does the following:
- Deinitializes the submodule.
- Deletes the submodule’s metadata stored in
.git/modules/. - Removes the entry from the repository.
Step 2: Add the Directory as a Normal Folder
Now, you can manually add the folder back as a regular directory.
Ensure it’s not ignored Check your
.gitignorefile to make suredotfiles/.config/emacsis not excluded.1$ cat .gitignore | grep dotfiles/.config/emacsIf found, remove the line and save.
Re-add the directory as normal files
1$ git add dotfiles/.config/emacs 2$ git commit -m "Converted emacs directory from submodule to normal folder"
Step 3: Ensure the .gitmodules File is Updated
Since .gitmodules stores submodule information, remove its reference:
1$ sed -i '/dotfiles\/.config\/emacs/d' .gitmodules
2$ git add .gitmodules
3$ git commit -m "Removed submodule entry from .gitmodules"
Step 4: Push the Changes
Now push everything back to your remote repository:
1$ git push origin main # Change 'main' to your actual branch
Step 5: Verify Everything Works
Clone the repository in another location to check if the folder appears as a normal directory:
1$ git clone <your-repo-url> test-repo
2$ ls test-repo/dotfiles/.config/emacs # Should show files instead of an empty folder
Now your dotfiles/.config/emacs directory is treated as a regular directory instead of a submodule! 🚀 Let me know if you run into any issues.