DEV Community

Sanchita Paul
Sanchita Paul

Posted on

Multiple GitHub accounts on the same computer

Sometimes we face one common problem which is maintaining our multiple github account. I face this too.
We can do it in many ways. Some generate ssh key for their each account and so on. I am just sharing one way how we can use multiple git account for our multiple projects. Let's dive into it.

First of all we need to initialize the repository


git init

Enter fullscreen mode Exit fullscreen mode

Second we need to add all files to that repo


git add .

Enter fullscreen mode Exit fullscreen mode

Third we need to add our first commit


git commit -m "first commit"

Enter fullscreen mode Exit fullscreen mode

We need a token which we can generate from our account Settings/Developer settings/Personal access tokens . I used Token (classic). you can also use Beta as well

Now we will get a token

Finally time to push

git push https://user-name:your-token@github.com/user-name/reponame.git

Enter fullscreen mode Exit fullscreen mode

For example


git push https://saanchita-paul:token12345token@github.com/saanchita-paul/polymorphic.git

Enter fullscreen mode Exit fullscreen mode

sometimes it may say to use


git push --set-upstream git push https://user-name:your-token@github.com/user-name/reponame.git

Enter fullscreen mode Exit fullscreen mode

It's because git push --set-upstream is a command used to push your changes from a local Git repository to a remote Git repository and set the branch you're pushing to as the default upstream branch.

When you first create a branch in your local Git repository and want to push it to a remote repository, you need to specify the upstream branch using --set-upstream or -u option. This allows Git to know where to push the changes and which branch to track.

Happy Coding 🎉

Top comments (0)