PowerShell & Git Command Reference for Persistent Tokens
When working across multiple PowerShell sessions, temporary environment variables disappear when the terminal closes. Here is a quick reference guide for storing your GitHub Personal Access Token (PAT) permanently, managing remotes, and force-syncing Git branches.
1. Saving Your Git PAT Persistently in PowerShell
Instead of manually setting session variables every time, store your token directly in your Windows User Environment variables:
# Save your token permanently to your Windows profile
[System.Environment]::SetEnvironmentVariable("GITHUB_PAT", "your_actual_token_here", "User")
# Verify the persistent token in a new terminal session
echo $env:GITHUB_PAT
2. Configuring Git Remote with Environment Variables
Bind your repository remote origin using your persistent token variable securely:
# Set the remote URL using the PowerShell variable
git remote set-url origin "https://ananyaja:$env:GITHUB_PAT@github.com/ananyaja/linux-system-inspection-and-automation.git"
# Verify your remote configuration securely
git remote -v
3. Standard Git Workflow & Force-Syncing Remotes
When dealing with divergent branch histories or structuring deployments, use these commands to sync clean states:
# Stage all changes and commits
git add -A
git commit -m "Standardize repository files and configuration"
# Force push your local branch directly to the remote branch
git push origin master:main --force
Comments
Post a Comment