0

So, I have 2 gitLab accounts, we'll name them acc1 and acc2. I was working on a project that I have pushed to acc1. Now, I switched the project and I want to push it to acc2. The problem is that, when I commit (I have changed user.email, user.name and origin remote), it is aware only of the branches of acc1. Is there a way to "logout" from git?

2 Answers2

1

I have finally found out how to do this. All you have to do is use rm -rf .git and git init again

  • Yes, all the configurations are stored in .git directory -> config file. Once you delete it older data is gone and you have a fresh project. – 5eeker Feb 17 '21 at 07:01
0

I assume you are working locally with git. Hence it is important to understand how git works. Git is decentralized and each local git repository can push to multiple so called remotes, if the projects are related. Or if you have multiple unrelated projects, i recommend to use one directory per project.

Most projects only have one remote called origin, you can check that via:

git remote -v

if you want to push to another repository you need to add another remote

git remote add <name> <url>

now you can specify while pushing to push to another remote via

git push <remote> <branch>

If you want to get a list of the remote branches etc you also need to fetch from there

git fetch <remote>

This practice is really common in the OpenSource world, and usually on GitHub and GitLab the practice to contribute to other repositories.

You have to be aware, that the History needs to be somewhat in sync, else you will have problems pushing to the other repository. Therefor i can recommend to read Git refusing to merge unrelated histories on rebase

GitHub Docs and GitLab Docs explain this for forking.

Simon Schrottner
  • 4,146
  • 1
  • 24
  • 36
  • i just saw that i miss read some parts of the question, and that you tried to change the remote too - i added the fetching part for updating - but i still think the answer itself will help others, who stumble upon this question – Simon Schrottner Feb 17 '21 at 07:00