If you created a public repository in your GitHub account, you can easily send your local code files to that repository without any additional setup.
But If you want to upload your files to a private repository, so that no one can see and access your code, you need to do some simple settings.
First, you need to generate SSH keys on your computer and you have to add that keys to your GitHub Account.
So that Github can understand, the system accessed that private repository is yours.
Step 1: You must install Git on your system & configure the git username and email
Before that, your system must have the Git application.
Make sure to Download and install the Git application on your system.
Open Cmd and type the following commands to set your username:& email address for Git
git config --global user.name "FIRST_NAME LAST_NAME" git config --global user.email "[email protected]"
Replace the “FIRST_NAME LAST_NAME” with your actual name and “[email protected]” with your email address.
Step 2: Generate SSH keys on your computer and add that keys to your Github account.
To Generate SSH keys
Open Git Bash and paste the following code
$ ssh-keygen -t ed25519 -C "[email protected]"
Just replace the email with your email.
Just press Enter, Enter, Enter
It will automatically generate the SSH key.
Now you have to add that SSH keys on your GitHub account
- Then go to Github.com
- Sign into your account
- On the top right corner of the screen, click your profile image and Choose Settings.
- On the left side of the screen, you can see the “SSH and GPG keys” option in the Access section.
- Just click it.
- Press the New SSH key button and add the SSH keys you generated o your computer.
Step 3: Create a private repository on GitHub and upload the files from your local computer to that repository
Now let's see how to upload files in a private repository
First, create a new private repository..
- Go to github.com and Sign into your account.
- Then Click the New button on the left side of the screen to create a new repository.
- Enter the repository name and select the Private option.
- Then click the “Create repository” option.
Now you have a private repository without any files in it.
Then on your system, go to the folder you want to upload.
Right-click and choose “Git Bash here”. The type the following commands
git init git add . git status
Then you can find the following commands in your private repository, just select the SSH tab and copy and paste the following codes
git commit -m “first commit” git branch -M main git remote add origin [email protected]:”username with git” git push -u origin main
That’s all. Your Files will be uploaded to that private repository.
Sometimes you will get an error message like this
The authenticity of host 'github.com (18.104.22.168)' can't be established. ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])?
To fix this problem, just paste the following code in Git bash
ssh-keyscan github.com >> ~/.ssh/known_hosts
Now try to push the code again using the following command
git push -u origin main