Skip to main content

Command Palette

Search for a command to run...

Git and github

Published
2 min read
U

Writing blogs on what i learnt so that i could refer them later :)

github

Fix GitHub Push Error using SSH

If git push fails with Repository not found, switch from HTTPS to SSH.

Steps:

  1. Check for an existing SSH key:
    ls ~/.ssh → if id_ed25519 exists, reuse it.

  2. Generate a key (if needed):
    ssh-keygen -t ed25519 -C "shaikuzma2023@gmail.com"

  3. Start SSH agent & add key:
    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/id_ed25519

  4. Copy public key:
    pbcopy < ~/.ssh/id_ed25519.pub

  5. Add key to GitHub → Settings → SSH and GPG keys.

  6. Test connection:
    ssh -T git@github.com → should authenticate successfully.

  7. Change repo remote to SSH:
    git remote set-url origin git@github.com:uzma-dev/Portfolio.git

  8. Push code:
    git push -u origin main

Why this works:
HTTPS needs credentials/tokens. SSH uses key-based authentication—clean, secure, and password-free.

git

create a new repository on the command line

echo "# Portfolio" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/uzma-dev/Portfolio.git
git push -u origin main

OR push an existing repository from the command line

git remote add origin https://github.com/uzma-dev/Portfolio.git
git branch -M main
git push -u origin main

git push -u origin main

  • Pushes your local main branch to the remote repo origin (GitHub).

  • -u sets an upstream link between local main and origin/main.

  • After this, you can use just git push or git pull without extra arguments.

  • Usually run once per branch.

to create a new branch :

git checkout -b feature-branch-name
or new syntax
git switch -c feature-branch-name

after that add commit and push the new branch git push -u origin feature-branch-name.