While working with git you can either enter username and password at each time you perform operations like git pull, push, etc. In the following example, I will be using github repository for remote with local repos on my Mac. I will also be using my own account and company user account to access two different github accounts and their respective repos.
One account only and access to its respective repositories.
Here just modify your ~/local_repo/.git/config file to either use https or ssh connection. Typical config looks like
By default when cloning is done with git clone command the config file generated will have entry of "url = https://github.com" (assuming you are cloning from github repo). See how to switch from https to ssh for a given repo or you can comment out the line as above and enter "ssh" link shown above in the example. Git config (git_config) has too many options and you can control different aspects of git behavior.
Among many but another scenario is when using two or more different github accounts from the same computer/system. Under this ~/.ssh/config file will be useful. Here ssh setup is required and https doesn't help much.
Other variations would be multiple accounts with different service providers not just github. This is little bit easier than having multiple accounts with same service providers.
Example: Github two accounts - doe_work and doe_personal and for each account you create two separate ssh keys with ssh-keygen.
> ssh-keygen -t rsa -f ~/.ssh/id_rsa_doe_work_git -C "Job new_key doe@company.com"
> ssh-keygen -t rsa -f ~/.ssh/id_rsa_doe_personal -C "Personal key"
Now configure both accounts to use ssh and its config - ssh_config. Important section in ssh_config is the "host" which is a string pattern to match in the config file to get it's respective options/ variables. You obviously should add the newly created public keys to github under settings->SSH Keys->Add SSH Key. Sample pub key for above.
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDdnbxKkCrYUv3YbutC2Dw6jIhQWLNIzNA3Ec6inlmrngwB33fCaEP4ZiOzPq8A0BRBCyV HYhC3txA9Jn1tRXVZ4tUGEslvN2qF2HNXJhSx8V5Vk1r3LmWe1uehOjAekSK0apELpkafSwigzgkm9oAmbNQ5p0N1e8ar/TXbOOzWVMRu9K G/fILuHf90UZ4H5hOrZov9eZSwabnSMvORirizFXYZPp/FQ30fV3wZJKJoNnmOY+/txjnNc+mikYiezjeA66vWlDGfJQ+Xlb+i1bnXoxBfv hrE/nSuSUVNmGy0bYPOFwbxPrnz0jFGCgdUh7KfKD2yE/gc0abhW0nyxkP Job new_key doe@company.com
The three configuration files discussed are used by git to perform handshake with remote server and authenticate for each of git pull, push, fetch etc.
Simple setup:
One account only and access to its respective repositories.
Here just modify your ~/local_repo/.git/config file to either use https or ssh connection. Typical config looks like
DW Schema Sizes
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true [remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* # url = https://github.com/USER_OR_ORG_NAME/REPO.git url = ssh://git@github.com/USER_OR_ORG_NAME/REPO.git [branch "master"] remote = origin merge = refs/heads/master ... ...With command line git pull/push and ssh pub-key setup at github.com. See how to provide the pub-key to github. If you already have a ssh key and you would like to use the same just add entry in the ~/.ssh/config file with corresponding entries. See below for more details on how to do this.
By default when cloning is done with git clone command the config file generated will have entry of "url = https://github.com" (assuming you are cloning from github repo). See how to switch from https to ssh for a given repo or you can comment out the line as above and enter "ssh" link shown above in the example. Git config (git_config) has too many options and you can control different aspects of git behavior.
Multiple account setup:
Among many but another scenario is when using two or more different github accounts from the same computer/system. Under this ~/.ssh/config file will be useful. Here ssh setup is required and https doesn't help much.
Other variations would be multiple accounts with different service providers not just github. This is little bit easier than having multiple accounts with same service providers.
Example: Github two accounts - doe_work and doe_personal and for each account you create two separate ssh keys with ssh-keygen.
> ssh-keygen -t rsa -f ~/.ssh/id_rsa_doe_work_git -C "Job new_key doe@company.com"
> ssh-keygen -t rsa -f ~/.ssh/id_rsa_doe_personal -C "Personal key"
Now configure both accounts to use ssh and its config - ssh_config. Important section in ssh_config is the "host" which is a string pattern to match in the config file to get it's respective options/ variables. You obviously should add the newly created public keys to github under settings->SSH Keys->Add SSH Key. Sample pub key for above.
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDdnbxKkCrYUv3YbutC2Dw6jIhQWLNIzNA3Ec6inlmrngwB33fCaEP4ZiOzPq8A0BRBCyV HYhC3txA9Jn1tRXVZ4tUGEslvN2qF2HNXJhSx8V5Vk1r3LmWe1uehOjAekSK0apELpkafSwigzgkm9oAmbNQ5p0N1e8ar/TXbOOzWVMRu9K G/fILuHf90UZ4H5hOrZov9eZSwabnSMvORirizFXYZPp/FQ30fV3wZJKJoNnmOY+/txjnNc+mikYiezjeA66vWlDGfJQ+Xlb+i1bnXoxBfv hrE/nSuSUVNmGy0bYPOFwbxPrnz0jFGCgdUh7KfKD2yE/gc0abhW0nyxkP Job new_key doe@company.com
... ServerAliveInterval 60 ServerAliveCountMax 60 ... Host github.com HostName github.com # User doe_work IdentityFile ~/.ssh/id_rsa_doe_work_git ... Host github-mine HostName github.com # User doe_personal IdentityFile ~/.ssh/id_rsa_doe_personal ... Now in each repo change/.git/config to use the above ssh/hosts. [remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = ssh://git@github.com/USER_OR_ORG_NAME/REPO.git and [remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = ssh://git@github-mine/USER_OR_ORG_NAME/REPO.git
The three configuration files discussed are used by git to perform handshake with remote server and authenticate for each of git pull, push, fetch etc.
Pretty! This was a really wonderful article. Many thanks for supplying
ReplyDeletethis info.
my webpage Free Download IDM
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeleteData Science Training in Chennai
Data science training in bangalore
Data science online training
Data science training in pune
Data science training in kalyan nagar
It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
ReplyDeleteDevops training in Chennai
Devops training in Bangalore
Devops Online training
Devops training in Pune
After seeing your article I want to say that the presentation is very good and also a well-written article with some very good information which is very useful for the readers....thanks for sharing it and do share more posts like this.
ReplyDeletejava training in annanagar | java training in chennai
java training in marathahalli | java training in btm layout
java training in rajaji nagar | java training in jayanagar
java training in chennai
This comment has been removed by the author.
ReplyDeleteI am sure this post has helped me save many hours of browsing other related posts just to find what I was looking for. Many thanks!
ReplyDeleteangularjs Training in online
angularjs Training in bangalore
angularjs Training in bangalore
angularjs Training in btm
Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic.
ReplyDeletepython training in chennai
python training in Bangalore
Python training institute in chennai
This looks absolutely perfect. All these tiny details are made with lot of background knowledge. I like it a lot.
ReplyDeleteangularjs Training in marathahalli
angularjs interview questions and answers
angularjs Training in bangalore
angularjs Training in bangalore
angularjs online Training
angularjs Training in marathahalli
The blog is really satisfying the queries for the Beginners very easily.
ReplyDeleteData Science Training Course In Chennai | Data Science Training Course In Anna Nagar | Data Science Training Course In OMR | Data Science Training Course In Porur | Data Science Training Course In Tambaram | Data Science Training Course In Velachery
You have provided a nice article, Thank you very much for this one. And I hope this will be useful for many people. Salesforce Training Cretification
ReplyDelete
ReplyDeleteThanks For Sharing The Wonderfull Content With Us !
Best Degree College In Hyderabad
Best Degree College In Attapur
Top And Best BBA College In Hyderabad
Top And Best B.Com College In Hyderabad
Thank you for sharing the article. The data that you provided in the blog is informative and effective.
ReplyDeleteJava training in chennai
python training in chennai
web designing and development training in chennai
selenium training in chennai
digital-marketing training in chennai
very nice blogs!!! i have to learning for lot of information for this sites...Sharing for wonderful information. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing
ReplyDeleteYour info is really amazing with impressive content..Excellent blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a nice blog
it is really explainable very well and i got more information from your blog.