Wednesday 24 August 2022

How to git push origin main in ubuntu?

Github is no longer support the password authentication.

Therefore we need to use ssh authentication as suggested by github.


1. open a terminal

https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

ssh-keygen -t ed25519 -C "your_email@example.com"
> Enter a file in which to save the key (/home/you/.ssh/algorithm): [Press enter] 
> Enter passphrase (empty for no passphrase): [Press enter]
> Enter same passphrase again: [Press enter]
 
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519  
cat ~/.ssh/id_ed25519.pub

2. Follow this page, to add the ssh key into github:-

https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account 

3. Authenticate SSH connection
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/testing-your-ssh-connection
ssh -T git@github.com
> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
> RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
> Are you sure you want to continue connecting (yes/no)?
> Hi username! You've successfully authenticated, but GitHub does not
> provide shell access.
  
4. Set the remote URL
git remote set-url origin git@github.com:username/repo_name.git 
 
5. Git Push the files into github repo
git add .
git commit -m "what you have done"
git push origin main
 
(if you want to pull again the repo, make sure you have downloaded the repo before, cd to that repo folder in your computer and pull it)
git pull origin main
 
(otherwise you need to git clone the repo again)
git clone xxx.git
 
Done!

No comments:

Post a Comment