Handle Multiple git accounts in a system
Hi friends, in this post I will share how to use multiple git accounts on our machine.
I hope, most of the developers are like me to have their own GitHub account and their company's git account.
By default, we can configure our system or laptop with only one git account. So whenever we are working with repositories under that git account we do not need to give a username and password Token for each git operation — git pull, push, fetch.
But sometimes we may need to work on repositories which are in other git providers such gitlab or Azure Git. In that case, we need to give a git username and password for every git operation (Communicating with git cloud).
To avoid giving username and password tokens for every git operation, we can configure username and password tokens with those repositories.
Git Configuration with the project Repo
Here, I have a GitHub repository that is connected to my personal GitHub account, but my system does not configure my personal GitHub account. So I can not use the SSH method to add a remote URL in the the project folder. So I need to use the HTTPS method to add a remote URL in the project folder.
If I want to push my code, it will ask username and password. You can see this in the above image.
By entering my username and password, I can push my code. Here, I need to do this for every push, pull, and fetch operation. Is it not redundant work?
How do we avoid the repetition?
- Open the git config file of the project
vim .git/cofig
It will open the following file. Here I added a Username and Password.
2. Here we need to add Username and Password.
url = https://github.com/EdisonDevadoss/javascript-problem-solving.git
By default it shows like this above, we need to add <Username>: and <Password>
Then save the file. Now run the git push command.
Now It will not ask us to enter a username and password for any git operation.
I hope this tip is helpful.
Thank you for reading. Have a nice day!