- Create a repo on GitHub (or get its clone URL).
- On your machine: generate SSH key or prepare a Personal Access Token (HTTPS).
- Initialize or open your local repo, add remote (
origin), and push (git push -u origin main). - Verify and use the normal fetch/pull/push workflow.
Replace your username & email with your actual username and email ID:
git config --global user.name "Your User_Name"
git config --global user.email "your@email.com"- Generate an ed25519 key — replace your email with your actual email ID:
ssh-keygen -t ed25519 -C "your@email.com"
#Accept default (~/.ssh/id_ed25519) or give a custom name if you already have keys- Start the SSH agent and add the key:
# Start agent
eval "$(ssh-agent -s)"
# Add key to agent
ssh-add ~/.ssh/id_ed25519- Add SSH config(Optional):
cd ~/.ssh/config
Host github.com
HostName github.com
User git
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519
ServerAliveInterval 60
ServerAliveCountMax 5
TCPKeepAlive yes
- Copy the public key and add it to your GitHub account:
cat ~/.ssh/id_ed25519.pub- Test the connection:
ssh -T git@github.com- GitHub no longer accepts passwords for HTTPS Git — use a PAT.
- Create PAT in GitHub: Settings → Developer settings → Personal access tokens.
- Example:
git clone https://github.com/OWNER/REPO.gitFind repo clone URL on GitHub → Code button.
On GitHub: New repository → follow commands to push existing repo.
cd ~/my-project
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin git@github.com:OWNER/REPO.git
git push -u origin main git remote add origin git@github.com:OWNER/REPO.git
git remote -v
git remote set-url origin git@github.com:OWNER/NEWREPO.git
git remote remove origin git fetch origin
git pull origin main
git config pull.rebase true
git push origin main git branch --set-upstream-to=origin/main main
git push --set-upstream origin feature/x
git branch -vv- Permission denied (publickey) → Check SSH key, agent, GitHub settings.
- Host key verification failed → Update known_hosts.
- Password authentication removed → Use PAT.
- Stale remote-tracking branches → git remote prune origin.
- Prefer ed25519 keys.
- Use --force-with-lease instead of --force.
- Never commit secrets.
ssh-keygen -t ed25519 -C "your@email.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub #Copy the public key and add it to your GitHub account
ssh -T git@github.com
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin git@github.com:OWNER/REPO.git
git push -u origin main
git remote set-url origin git@github.com:OWNER/NEWREPO.git
git remote remove origin
git fetch origin
git pull origin main
git push