To prevent re-entering of password in git pull
or git push
, you can edit your .git/config
file in the project and update the remote url
value. Add user token before hostname github.com
.
Solution
1. Generate user token for your project on Github.com.
2. Create expiry of this token according to your use case. You can create a Never Expire token but it’s better to keep a token for 30 days as security point of view.
3. Open .git/config
file in your project. The content will look something like this –
[core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true ignorecase = true [remote "origin"] url = https://github.com/akamittal/myrepo.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "main"] remote = origin merge = refs/heads/main [branch "gh-pages"] remote = origin merge = refs/heads/gh-pages
4. Check the highlighted line in above block. It’s the remote url of the repository. Before the hostname (github.com) add your newly created user token appended by @
. Like this –
[core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true ignorecase = true [remote "origin"] url = https://[email protected]/akamittal/myrepo.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "main"] remote = origin merge = refs/heads/main [branch "gh-pages"] remote = origin merge = refs/heads/gh-pages
5. Save the file and now you won’t need to enter password every time you git push
or git pull
.