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 "MY_NAME@example.com"
Replace the “FIRST_NAME LAST_NAME” with your actual name and “MY_NAME@example.com” with your email address.
Note: When typing a command on cmd, if it shows the error like”‘git' is not recognized as an internal or external command, operable program or batch file.' Then you need to add Git path in environment variables. Reference
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 "your_email@example.com"
Just replace the email with your email.
Just press Enter, Enter, Enter
It will automatically generate the SSH key.
Note: It will show the public key saved location on your system. Go to that location. Open the file in Notepad. Copy the whole key and paste it into Github Settings.
Now you have to add that SSH keys on your GitHub account
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..
For that
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”. Then type the following commands
git init git add . git status
Then you can find the following commands in your private repository, select the SSH tab and copy and paste the following codes in Git Bash. Note: This is an example code. You can find the code like this in your private repository.
git commit -m “first commit” git branch -M main git remote add origin git@github.com:”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 (20.207.73.82)' 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, 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
© 2024 Webapptiv. All rights reserved.