This write-up will explain the procedure to push to GitHub without a password using the SSH key.
How to Push to GitHub Without a Password Using SSH Key?
To push local changes to GitHub without a password, first, switch to the local directory. Then, copy the SSH key of the desired remote repository from GitHub and add it to the local repository. Next, download the latest changes of the remote branch in the local repository. At the end, push the local content to the particular GitHub repository.
Note: If you do not have the SSH key for your remote repository, check out our dedicated post about generating the SSH key.
Step 1: Go to Local Git Directory
Redirect to the selected repository by typing out the following command:
Step 2: Copy Remote SSH Key
Then, switch to GitHub, choose the required remote repository and copy its “SSH URL” to the clipboard:
Step 3: Add Remote SSH URL to Local Repository
Now, connect the remote repository with the local repository by running the given-below command:
Step 4: Verify Remote URL
Next, verify whether the remote URL has been added or not:
According to the below-given output, the remote URL has been added successfully:
Step 5: Fetch Remote Origin
Now, use the “git fetch” command to download the updated version of the remote repository:
It can be observed that the content of the origin has been fetched:
Step 6: Pull Remote Branch
Get the latest content or recent changes of the GitHub particular branch:
Here, the“–allow-unrelated-histories” option is used for not changing the history of the repository:
Step 7: Push Local Content to GitHub
At last, push the local changes to the selected remote repository:
In the above-stated command, the “–set-upstream” option is used when the developers are pushing a local branch for the first time. As you can see, the local changes are successfully pushed to the remote repository without providing a password:
We have learned about pushing local content to GitHub without a password using the SSH key.
Conclusion
To push the local content to GitHub remote repository without using the password, first, open the GitHub remote repository. Then, copy and add the SSH URL of the desired repository to the local repository. After that, fetch the updated remote content and download the latest remote branch changes. The last step is all about pushing the local changes to the particular remote repository. This write-up explained the method to push to GitHub without a password using the SSH key.