Change upstream of local (hg-git) clone from (github) original to fork - github

I discovered an OSS project I've contributed to had moved to github. I installed hg-git and cloned a local repo from the git:// URL; then I made changes.
I then realized I really wanted my own github fork, so I made one; but I haven't been able to figure out quite how to switch my existing local repo. I've changed the local repo settings to use the git:// URL of my fork, and it can pull; but I can't push my changes up. It tells me to use the https:// URL, but when I make that change, I can neither pull nor push -- I get an error 406, "not acceptable."
The work done in the local repo is minimal, so I can redo it, but it'd be simpler if the local repo and my fork could just connect now.
UPDATE
I've installed Github for Windows so I could manage the SSH key. It generated a key (github_rsa) and attached it to my Github account.
I edited the hgrc file and added a [ui]ssh= setting pointing to the local git 'ssh' command (buried down in %APPDATA%\Local\Github).
With this, if I go into a "git-shell" window, which I guess spawns ssh-agent, then I can enter commands such as "hg incoming" and the connection is made. So I've got the remote repo URL right, and within the git-shell ecosystem, I've got the SSH keys set up right.
From a regular CMD.EXE window, the same command yields "Permission denied (publickey)". From TortoiseHg, the same error appears when I try an "incoming" action. I'd prefer to keep using TortoiseHg, but I'm not sure how to get it to use SSH.
FINAL UPDATE
For some reason, TortoisePlink doesn't want to play with github's SSH server, at least not with the Github-for-Windows-generated key. So I still have Github for Windows installed (not necessarily a bad thing, but superfluous to what I wanted to do).
To get hg and TortoiseHg to connect, I had to modify my project settings:
[ui]
ssh = %USERPROFILE%\AppData\Local\GitHub\<salt>\bin\ssh -i %USERPROFILE%\.ssh\github_rsa
That is: point to the SSH command, installed with portable GitHub, and specify the github-generated key on the command line. With this configuration, I don't need ssh-agent to be running.

You need to push via ssh, meaning you need to push via:
hg push git+ssh://git#github.com/<login>/<repo>
Note the usage of git# instead of your login in the first part of the URL. This actually matters; the server will figure out your credentials via the supplied SSH key.
You may also have to add your ssh key to your GitHub account first (per step 4 of this page).
This assumes that you created a fork of the original GitHub repository via the GitHub UI; pushing to an empty repository with hg-git may require additional steps.

Related

Why is it appearing like I have pushed my code to github but I got to my profile and the code is not there?

What am I doing wrong?
Why will my code not show on github even though it appears to have pushed saying clean tree.
What am I supposed to be entering when it asks for git credentials osxkeychain?
Hello I have been watching video after video and reading the documentation on github and how to use it but nothing seems to be working. I have created a repo in my account and done the following:
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/stephBrandon/PythonNumberGuessingGame.git
git push -u origin main
it responded by saying initialized empty git repo in my folder which is true when hitting ls -a there is a .git file and there is a readme now as well
But when checking on my github none of the code it there and in the terminal it seems to be trying to access my old git hub account instead of my new one and I have no idea what to do now.
remote: Permission to stephBrandon/PythonNumberGuessingGame.git denied to stephanieBrandon.
fatal: unable to access 'https://github.com/stephBrandon/PythonNumberGuessingGame.git/': The requested URL returned error: 403```
I had issues with the keycode and went into my key chain to see if I could change it there or if I was entering the wrong password but the one I had I deleted and it wont allow me to add another like some other videos I have watched.
Please help. I just want to know how to start using GitHub as I am in year 2 of my program and want to have a visible portfolio of my work without the frustrations of not figuring out how to use GitHub and it always seeming to take longer to upload to GitHub then the projects themselves sometimes.
If I am missing something in my explanation above here is a copy of the terminal
```(base) stephaniebrandon#Stephanies-MacBook-Pro-2 Lab4Random % git commit -m "First commit for Python Guessing Game"
[main e955053] First commit for Python Guessing Game
1 file changed, 44 insertions(+)
create mode 100644 lab4.py
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 Lab4Random % git remote add origin https://github.com/stephBrandon/PythonNumberGuessingGame.git
error: remote origin already exists.
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 Lab4Random % git remote add origin https://github.com/stephBrandon/PythonNumberGuessingGame.git
git branch -M main
git push -u origin main
error: remote origin already exists.
remote: Permission to stephBrandon/PythonNumberGuessingGame.git denied to stephanieBrandon.
fatal: unable to access 'https://github.com/stephBrandon/PythonNumberGuessingGame.git/': The requested URL returned error: 403
(base) stephaniebrandon#Stephanies-MacBook-Pro-2 Lab4Random % ls -a
. .. .git README.md lab4.py```
Additionally, when I try to do
```git push -u origin main```
it doesn't do anything but enter a loop that I have to control c to get out of.
If you are okay with using SSH instead of HTML, this should be the easiest way. This is assuming you have not local .git folder (you can delete it if you don't have git history you'd like to save).
Part 1: Set up SSH with GitHub
First, open your terminal and run this command:
ssh-keygen -b 4096 -t rsa
When it asks you for a file name and save location, just hit ENTER to use defaults. Unless you feel it is necessary you can skip the password requirement the same way.
This will create a new (hidden!) folder named .ssh and two files in it: id_rsa and id_rsa.pub. id_rsa.pub is your public key. This is how you will authenticate with GitHub. Never share your private key (the other file).
Now, go to GitHub and sign in normally. Then, go to your profile settings (pictured below).
Then to this setting...
And hit this green button:
Give it any title you'd like, such as the name of your computer, and paste in the contents of your id_rsa.pub file into the box and hit "Add SSH key". You should be able to open either of the two rsa_id files with any text program.
Part 2: Setting up a Repo
In my experience, the easiest way to get Git configured correctly is to do this method rather than setting the upstream yourself.
First, make a new repository on GitHub. It doesn't matter if it's private or public, but add at least one file (such as a readme or .gitignore) to generate the first commit.
Now, you should be directed to your new repo. If you get a weird screen telling you to run some commands you likely didn't add any files when setting up the repo.
Assuming that you see the page, however, click the "code" button on the top right and select SSH. Copy it to the clipboard. (pictured below)
Part 3: Setting up your local repo
Open your terminal of choice and run
git clone git#github.com:[your details here].git
It should clone the repo and set the upstream for you. If you get an error here you likely have issues with your SSH settings.
Once you have the repo cloned, drag in any project you'd like and treat it like normal!
git status
git add *
git commit -m "Your message"
git push
Hope that works for you! Let me know if you have any problems.

Rstudio: Changing origin for git version control of project

I originally set up git in Rstudio while enrolled in the Data Scientist's Toolbox course at Coursera. Unfortunately, I did this in my phd project. The repository no longer exists on github. I am now attempting to write my thesis in rmarkdown using knitr and bookdown. I would like to use version control, both to learn proper git workflow and to have a structured back up of everything I have done in my thesis. However, I have been unable to change the version control repository in Rstudio.
I am unable to change this in the Tools > Version control > Project setup > Git/SVN menu. The Origin: textbox is unchangable.
I tried creating a new project using the old phd project's working directory. This also cloned the version control settings.
How do I change the origin to accomplish what is described above?
Git, Github and Rstudio are different things. You could use git as local version control tools. You might connect your local repo to Github account which is based on git by push/pull. Rstudio just makes a user interface for git and supplies the function to push the repo into remote server based on git to make version control(not only Github, but also Gitlab).
So for your issue, if you do not want to pay for github for a private repo, all of your code would be public and I don't think it is good before your finally finished your thesis. But version control could be made locally with git only. Just use git shell to control the version.
However, as a student, github could support private repo here for you. Just register and find your student package. Then just remove the url for remote repo after you cd to your workdir in command line, use the following code to find your remote url(mostly you might fing origin):
git remote -v
Then use this to remove them:
git remote rm origin
Now you could use version control locally. If you want to connect this repo to your remote github private repo, use this:
git remote add origin https://github.com/[YourUsername]/[YourRepoName].git
RStudio would find this information about git and support your following operation. Project in RStudio is different with git, although project support git as version control tool. So you need git in command line or shell to solve your problem.
This can be done by opening /your.project/.git/config
and editing the remote origin line(s), e.g. changing from git to https.
Restart Rstudio & you'll be prompted for your github username & password.
This is what worked for me for migrating from github to Azure
Go to the top right Git window in RStudio and click on the gear. Now click Shell (to open the terminal there).
#remove origin
git remote rm origin
#add new origin like Azure for me via HTTPS
git remote add origin https://USER#dev.azure.com/USER/PROJECT/_git/REPONAME
#push your local repro
git push -u origin --all
#in my case put in the PAT password if you needed to generate one.
After testing, I found some clue
Actually Rstudio is not really smart about this setting
It will first search for the git file in the Rproject folder where your Rporject file is located
if it could not, then it goes up to the folder contains your Rproject folder
However, for version control you only need coding files while RProject may contains some big files like .RData some pictures etc.
I don't find a way to manually disrupt this logic flow, the only thing you can do is to delete the current git repository setting files(which is .git folder and 2 other git setting files), then Rstudio may ask you if you want to init a new one.

Newbie Unable to clone repo

I've never used a VCS before and I'm attempting to set one up now.
I'm doing some Game Development with Unity3d. At first I googled how to set up VCS for Unity; and I found this: http://www.gamasutra.com/blogs/BurkayOzdemir/20130303/187697/Using_Unity3D_with_external_VCS_Mercurial__Bitbucket_step_to_step_guide.php
I followed it until it came time to clone the repository from within the hgTortoise workbench. When I hit the clone button after copying and pasting the URL to my repo from the BitBucket.org website I received an error: "Repository Git clone https:://username#bitbucket.org/username/projectName.git not found code: 255" and I do understand what an HTTP 404 error is.
Anyone who has used the internet knows it means the page could not be found.
I created this repo as private; is that why it could not find my repo?
Then I proceeded to follow the instructions at BitBucket's "BitBucket 101" help page. I installed Git, had already created a BitBucket account and repo, and the instructions which followed.
I stopped at the point where the help page said to enter some command line things in to Git Shell. I'm running Windows 8.1 and searches have shown me that particular program doesn't exist on this PC.
Am I doing this correctly? What am I doing wrong? All I need is to set up a VCS.
Git and Mercurial are 2 different distributed version control packages. They both use a command line interface. TortoiseHG (the package referred to in the step-by-step you linked to) is a GUI extension that's only used for Mercurial. (HG is the chemical symbol for Mercury, get it?!)
Bitbucket is an online repository that can host either Git or Mercurial repositories.
It looks like you created your repository on Bitbucket as a Git repo and not a Mercurial repo. Just delete the repo on Bitbucket (make sure you have a good copy of your source code) and recreate it as a Mercurial repo. Then work with TortoiseHG as instructed in the step-by-step.
The fact that it's a private repo doesn't matter. That just means it will only be visible to you (vs. everyone) and will require a password to push and pull changes via https or ssh.
Well, first of all, it seems that the tutorial that you seem to be using is based on using Mercurial instead of Git.
If you're comfortable with diving into the command line, you can download TortoiseHG, which is a Windows shell extension: http://tortoisehg.bitbucket.io/
However, there's nothing wrong with using SourceTree as well, which is a GUI-based interface for dealing with both Git and Mercurial repositories: https://www.sourcetreeapp.com/
FYI, if you downloaded Git for Windows, it should've provided you with a terminal called Git Bash that you can use for Git commands.

github - attempting to push/pull/update (not sure of the terminology) updated code from github to remote server via terminal/ssh mac os

So I have my local computer - where I've updated my (html/js/css) code, github (where I've pushed the updated code already by doing a git add + git commit + git push origin master) and then the server of the actual website which the code is for.
I've connected to the server via the command line terminal. I've already previously cloned the code to the server (by running the command git clone [REPO URL]) while logged in to the server via SSH, so the (un-updated-)files are there.
But now that I've updated the code, and pushed that update to github, how do I now update or push the repo/code/updated-github-code to the server???
I'm currently looking at the terminal with
[~]#
^ showing. I tried to git clone [REPO URL] again, but then I get the msg:
fatal: destination path 'name of my file' already exists and is not an empty directory
Am I missing or overlooking a step? Well obviously I am but I could use some help please. Like I said I'm trying to update the code to the server so the actual website will reflect the changes I made to the code and so everything is in sync (local code, code pushed to github and hopefully/eventually the code on the server/website).
I am just learning this obviously, so go easy on me (I've spent almost the entire day learning to connect to the server via SSH in terminal)...
Also, feel free to correct my terminology...
Pull from github while ssh'd into the server using the link from the github repo "copy to clipboard" button on the web interface. If that doesn't work you could try wiping the repos folder on the server and cloning from scratch. But use that option with caution if downtime is unacceptable for this particular web app.

Netbeans fails to access GitHub using SSH key

My (newest) Netbeans (NetBeans IDE 7.3 (Build 201302132200)) seems to be failing completely, when I'm trying to access my own GitHub repo using SSH. It works without problems with HTTP URLs.
Since I've imported an existing local copy of GitHub repository (New > PHP Project with existing sources), created once with TortoiseGit, there were remote settings saved in local copy meta-data (probably in .git folder). So Netbeans offers option Select Configured Git Repository Location in Push to Remote Repository window. But is unsuccessful at that.
Tried following:
When I'm using SSH URL (git#github.com:user/reponame.git) and Password option, with account pass, Netbeans tries to connect GitHub (remote) and after circa 5 seconds throws error Cannot connect to the remote repository at git#github.com:user/reponame.git.
When using SSH URL with Private/Public Key option, Netbeans throws exactly the same error immediately, so I assume, that for some reason it doesn't even tries to connect GitHub.
What is even more strange (?), Netbeans is not asking for private key's passpharse. I've set it, but did not entered it to Netbeans deliberately, to test connection process. I was more than sure, that Netbeans will ask me to provide this passpharse, as it shouldn't be able to use private key without it. To my surprise, it hasn't asked for it and instead it thrown an error saying, that it can't connect GitHub. Of course, that was only a test. After entering correct passpharse, I'm getting exactly the same effects.
I've copied my repo's URL directly from GitHub website, without any modifications. It seems, that I can only use HTTP URL (https://github.com/user/reponame.git). This works and assures me that all items (URL, user, reponame, password, finally Internet connection) are OK. But, it seems, that Netbeans fails completely on SSH URL.
Above happens always, no matter if I select Select Configured Git Repository Location or Specify Git Repository Location in Push to Remote Repository window. No matter, what I'll do I can't access my repository via SSH in Netbeans and using HTTP is the only option.
I have created my private-public key pair using puttygen.exe from PuTTY's website. I saved private key in Netbeans installation directory and added public key to GitHub's SSH Settings page. I used step-by-step guide I normally use with TortoiseGit.
I don't know what else I could miss out or I'm doing wrong? Any idea?
For the record:
When generating keys with PuTTYgen, it's recommended for compatibility to export it as an OpenSSH key. This can be achieved by accesing Conversions > Export OpenSSH key menu.
After series of many tests, I found out that Netbeans:
Does not work to well with existing local copies of GitHub (or any other git) remote repositories.
Does not work at all with SSH keys generated by puttygen.
As for first, I had to remove entire folder cloned with TortoiseGit and clone the same repository using Netbeans-bundled tools (Team > Git > Clone). The same goes for Subversion (look here) -- so the general rule of thumb says, that when you're switching from another Git or SVN client to Netbeans, you should do a full, clean clone (or checkout) of remote repository as attempts to re-use existing copy will most likely fail.
As for second, follow instructions given in this GitHub article and use ssh-keygen (either from your local installation of Git for Windows, in case of Windows or from any other source) instead of puttygen -- SSH keys generated by it can't be used in Netbeans for setting up password-less login to GitHub.
As I wrote, I've been using TortoiseGit previously, which accepts and works well with puttygen keys, so it wasn't to obvious for me, that source of the problem is here.
After fixing this two problems (getting clean clone and generating correct keys), ale problems expressed in my question were gone and Netbeans works with GitHub repositories like a charm.
My solution was to use a the ssh-keygen with the PEM option:
ssh-keygen -t rsa -b 4096 -m PEM -C my#mail.xy
Netbeans 12 use JGit for the Git-tool and this supports only special kinds of ssh keys?