From local to Git (Private repository)
- First download git from official source (link)
- Install it.
- Now to Initialize private repository first you have to add SSH key in your local pc/laptop.
Steps to add SSH key from local to GitHub
- Open Terminal, use default and execute this command.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" #adding git hub Email
# it ask for folder name to add in that - Add folder name
# it ask for passPhrase(password) add that
# to get public key go to created folder and open "id_rsa" with notePad, open & copy
- To check where it is created check in this folder
c:\Users\<yourPC>\.ssh
# example
# c:\Users\Sanya-Lazy\.ssh
- There you have files names as
id_rsa
andid_rsa.pub
. open that .pub file
Add SSH Key to GitHub
- Login to your GitHub account.
- Go to your account settings by clicking on your profile picture in the top-right corner and select "Settings".
- In the settings sidebar, click on "SSH and GPG keys".
- Click on "New SSH Key" or "Add SSH Key" depending on what's available.
- In the "Title" field, provide a descriptive label for the new key, such as "Personal laptop".
- Set Key type to "Authentication key".
- Paste your public key into the "key" field.
- Click on "Add SSH key" to save the key to your GitHub account.
Easy access: Settings -> SSH and GPG keys -> Add SSH key -> Add Title(as "Laptop Name") -> Add Public key into the "Key" field -> click on "Add SSH key"
Check out this Images -
Now To add Project to Private Repository
- Create new private repository in GitHub.
- Now after Creating new project or with existing project, open terminal and run commands
- To Initialize git to your project
git init
- Add all files to git
git add .
- Add first commit message
git commit -m "first commit"
- Add branch name
git branch -M main # here you can use any branch name like main or master
- Add remote URL to your project.
git remote add origin https://github.com/<github-username>/<project-name>.git
- Now push to GitHub
git push -u origin main # here use your branch name
If above method doesn't work (use this method)
- First check is SSH key working or not, by using this
ssh -vT git@github.com
# it asks for password, that set when creating SSH key
- If it shows correct then it should show GitHub username or Email
- If GitHub username is showing then the SSH keys are working. Good
- Now try these commands to push project to GitHub Private Repository.
- Initialize git
git init
- Add files
git add .
- Now add commit message
git commit -m "first commit"
- Now before setting origin URL, first remove before added remote URL, if any
git remote remove origin
- Now add origin to project
git remote add origin git@github.com:<username>/<projectName>.git
# Example
# git remote add origin git@github.com:Sanya-Lazy/AwesomeProject.git
- Now set remote URL to project
git remote set-url origin git@github.com:<username>/<projectName>.git
# Example
# git remote set-url origin git@github.com:Sanya-Lazy/AwesomeProject.git
- Now push origin to GitHub
git push -u origin main
- To update git first you have to pull the changes and you have to push
git pull origin master
Some Useful Git commands
- To see remote URL
git remote -v
- To remove git from project
rm .git
# press "A" and hit enter
- If you got any erroring while adding SSH key, check for
.ssh
folder in Users. There you have files names asid_rsa
andid_rsa.pub
. open that .pub file
Happy Coding π΄ - Be Lazy
Contact DM - Twitter(X)
Contact Mail - sanya.san@myyahoo.com
Top comments (0)