-1

I want to use git with Visual Studio project. I already had a personal account which worked fine. Now my employer gave me a new account and visual studio is still trying to push to my personal account and gives me error on publish and syncs.

So i followed this tutorial:https://code.tutsplus.com/tutorials/quick-tip-how-to-work-with-github-and-multiple-accounts--net-22574

  • created new ssh key
  • created an identity to it
  • added that ssh key to my github account
  • added identity to ssh config

Now some of the things i am unclear about

i have created 2 origins + the default one which are origin (default) myorigin (not used) georigin (path:git@github-ge:ge/geweb)

when i type $ git config --global -l it gives me my correct(employer's) user.name and user.email

geweb is the name of my new repository the url of my repository is:https://github.com/ge/geweb.git

when i try pushing to georigin it says repository not found when i try pushing to origin it says error: src refspec master does not match any.

also, no where have i mentioned my second git account's username and password

also, i have 2 emails in my git account user.email in config is not the primary one. could that be the reason?

i am quiet confused at how it works end-to-end.

After failing to push i tried to unbind the project from source and deleted .git files from my project folder but team explorer is still showing unsynced commits and changes

the output of git remote -v is:

  • myorigin git@github-ge:ge:getWeb.git (fetch)
  • myorigin git@github-ge:ge:geWeb.git (push)
Samra
  • 1,815
  • 4
  • 35
  • 71
  • There are too many things that might be causing the problem. Consider narrowing and specifying your question. – Shaun Luttin Feb 16 '17 at 01:27
  • as a starting point : what is origin and what does git@github-ge represent in the path git@github-ge:ge/geweb – Samra Feb 16 '17 at 01:42

4 Answers4

2

Assume your private account and repo is https://github.com/my/repo.git and the second account and repo you want to use is :https://github.com/ge/geweb.git. The whole steps as below:

  1. ssh-keygen -t rsa -C "second account email address"
  2. Rename files for id_rsa, such as Enter file in which to save the key (/c/Users /.ssh/id_rsa): /c/Users /.ssh/id_rsa_ge
  3. In the directory c:\Users \.ssh copy the content of id-rsa_ge.pub to the second github account as SSH key.
  4. touch /c/Users /.ssh/config
  5. modify the config content as below:

Host github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa

Host github-ge HostName github.com User git IdentityFile ~/.ssh/id_rsa_ge

  1. clone your private repo by git clone https://github.com/my/repo.git
  2. git remote add geweb git@github-ge:ge/geweb.git
  3. git push geweb master or git push geweb master -f
Marina Liu
  • 36,876
  • 5
  • 61
  • 74
  • Dear i have already done all these steps and on git push geweb master i am getting a repository not found error!! This was my question in the first place – Samra Feb 16 '17 at 03:35
  • It should be `git@github-ge:ge/geWeb.git` instead of `git@github-ge:ge:geWeb.git`. – Marina Liu Feb 16 '17 at 04:58
  • Marina how do i edit the above?i want to use georigin that i defined previously as git@github-ge:ge/geWeb.git – Samra Feb 16 '17 at 05:14
  • You can delete the wrong url by `git remote rm myorigin` and `git remote add georigin git@github-ge:ge/geWeb.git`. If you added a remote georigin before, you should also remove it by `git remote rm georigin`. – Marina Liu Feb 16 '17 at 05:18
  • Thanks Marina the first part is sorted here! Now when i try to commit it shows me a list of irrelevant files and then says: "nothing added to commit but untracked files present". Does that mean i need to reconfigure my local repository? How? – Samra Feb 16 '17 at 05:32
  • Did the untrack files are which you added just now before commit? If yes, you should use `git add filename` or `git add .` and then commit the changes. – Marina Liu Feb 16 '17 at 05:45
  • No those are just irrelevant files (present in my c:/my documents) :S i cannot add files one by one coz its a big .sln with many projects – Samra Feb 16 '17 at 22:43
  • If you want all of them are version controlled by git, you can use `git add .` to add all files at once. – Marina Liu Feb 17 '17 at 01:18
  • Thanks Marina lemme try that out! – Samra Feb 17 '17 at 04:55
  • dah life is still not easy on me! Now it says: "Warning: Permanently added the RSA host key for IP address '192.30.xx.xx' to the list of known hosts. Enter passphrase for key '/c/Users/spadmin/.ssh/id_rsa_ge': To github-ge:/ge/geWeb ! [rejected] master -> master (fetch first) error: failed to push some refs to 'git@github-ge:/ge/geWeb' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing" – Samra Feb 17 '17 at 05:06
  • What were you doing when it showed the message? And you added remote `git@github-ge:/ge/geWeb`? It should `git@github-ge:ge/geWeb`, one more `/` in configuration. – Marina Liu Feb 17 '17 at 05:15
  • i removed the georigin, created new one with path git@github-ge:ge/geWeb.git then did "git pull georigin" it still gave me the same error. after this i did "git push georigin master" it gave me the same error "To github-gradexpert:Gradexpert/GradexpertWeb ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'git@github-gradexpert:Gradexpert/GradexpertWeb' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e..." – Samra Feb 17 '17 at 05:29
  • Please note This is my actual project folder. My local git repo is in c:/Users/spadmin/git – Samra Feb 17 '17 at 05:31
  • What's the output of `git remote -v` now? – Marina Liu Feb 17 '17 at 05:33
  • georigin git@github-ge:ge/geWeb (fetch) georigin git@github-ge:ge/geWeb (push) – Samra Feb 17 '17 at 05:35
  • How did you config the `github-gradexpert:Gradexpert/GradexpertWeb`? Why it hint something relate gradexpert when `git push georigin master`? – Marina Liu Feb 17 '17 at 05:39
  • consider gradexpert as ge (i was replacing all gradexpert with ge before posting a comment for privacy) – Samra Feb 17 '17 at 05:47
  • If gradexpert is your private repo, and ge is the second repo you want to use. Just use gradexpert as the way you used before. You can `git clone https://github.com/your_private/repo.git`, `git pull origin`, `git push origin`. The prerequisite is you were not over write `.ssh/id_rsa` and `.ssh/id_rsa_ge` (steps in my answer). – Marina Liu Feb 17 '17 at 05:58
  • well i am copying the url from my repo and it says "Cloning into 'GradexpertWeb'... remote: Repository not found." – Samra Feb 17 '17 at 06:08
  • If you use http protocol you can clone successfully. If you ssh protocol and failed to clone, you should check your id_rsa and if you have added a ssh key on github. – Marina Liu Feb 17 '17 at 06:55
  • i cannot find my id_rsa since the start (maybe its in another location) but i have successfully added id_rsa_ge and added the same to ge repository on github too. – Samra Feb 19 '17 at 22:22
  • This is a more elaborate error when i try to pull "From github-ge:ge/geWeb * branch master -> FETCH_HEAD fatal: refusing to merge unrelated histories " Also when i created repository i added the readme file – Samra Feb 19 '17 at 22:33
  • ok finally :D this is alll sorted out! Thanks MArina for your continuous support. I am posting an answer – Samra Feb 19 '17 at 22:50
1

what is origin and what does git@github-ge represent in the path git@github-ge:ge/geweb

origin is an arbitrary name given to a remote repository. It often represents the repository from which the local repository cloned itself.

For instance, if you ran git clone git@github.com:jquery/jquery.git, then you would end up with origin pointing at that cloned URI.

The git@github-ge part of your URI represents a user at a server (user@server). You can read about Git's protocols including the SSH protocol here.

For most people, that part of the URI means that Git is using SSH instead of HTTPS to communicate with the remote. Practically speaking, SSH requires an SSH key and running SSH agent, whereas HTTPS requires a username/password.

Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
  • ok so origin is remote repo at github! and both my georigin and origin point to the same one. Only that origin is http based and georigin is ssh based. Also, git@github-ge is added to my ssh config file only do i need to mention it somewhere else too? so now my question is when i try pushing to georigin it says "repository not found" note there is no repositoy name with this message just blank spaces. thanks a bunch!! – Samra Feb 16 '17 at 02:12
  • Please post in your question the output of `git remote -v` and then ping me back here. – Shaun Luttin Feb 16 '17 at 03:53
  • Hi Shaun, i have posted the output the origin showing in not georigin but myorigin which i am not using – Samra Feb 16 '17 at 04:36
0

So, it turned out that i had multiple problems with setting up my account.

  1. it was picking the wrong origin which was identified by Shaun and Marina

So, i removed the wrong one and added the correct one (georign)

  1. I had added a readme file to the default repository it was giving me error: hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

so i tried a pull before pushing and it turned out i had to --allow-unrelated-histories

git pull georigin master --allow-unrelated-histories

and then

git push georigin master

Thats it!!! (phew)

Samra
  • 1,815
  • 4
  • 35
  • 71
0

I manage to solve this by removing the Host * from my file, check ~/.ssh/config that doesn't work

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

Host github.com-workaccount
  AddKeysToAgent yes
  UseKeychain yes
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_github.com-workaccount

Now, check the one that works just fine

Host github.com
  AddKeysToAgent yes
  HostName github.com
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

Host github.com-workaccount
  AddKeysToAgent yes
  UseKeychain yes
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_github.com-workaccount

Thanks

Felquis
  • 101
  • 1
  • 4