Rename Github Repository - github

I want to rename my Github repository. Say old name is foo and I want to rename to bar
I understand how to rename the repository on the github site.
Github also advises doing the following on the local machine:
In addition to redirecting web traffic, all git clone, git fetch, or git push operations targeting the previous location will continue to function as if made on the new location. However, to reduce confusion, we strongly recommend updating any existing local clones to point to the new repository URL. You can do this by using git remote on the command line:
git remote set-url origin new_url
Question: Do I need to change the repository directory on my local machine manually? Or if I do a git pull will it automatically change the name on my local machine.
I found some old answers to this question (before github made some changes) but, in reviewing the Github documentation and googling I can't find a satisfactory answer to my question. so this is NOT a duplicate question
Thanks in advance.

Going off of your comment, it seems that you are concerned about the name of the directory on your local machine. In this case, you are free to name it whatever you want - the name of the directory containing the repository has no impact on the repository itself, as long as the specified remote within .git is accurate.
For updating the remote on your local machine to match your new repository on GitHub, refer to GitHub User Documentation

If I understand correctly, you're wondering whether you need to change the old repository URL (git#github.com:user/foo.git) to new URL (git#github.com:user/bar.git)
In that case, the simple answer is yes you do need to change that.
As your git clone link is now changed to the new repository and if you create a new repository that happened to have the old repository name all git commands will confuse and push and pull wrong data to/from wrong repository.
As for your question does git pull will do that for you, unfortunately no as this remote URL is hardcoded in the .git/config file and you can simply edit that and replace the link with new one without running any git commands.
[remote "origin"]
url = git#github.com:user/foo.git
fetch = +refs/heads/*:refs/remotes/origin/*

Another approach is to rename the remote GitHub repository from command-line, using the new gh repo rename command (from gh 2.3.0, Dec. 2021)
cd /path/to/local/repo
gh rename newName
It does also update your remote 'origin' URL: no need for a git remote set-url origin https://github.com/<you>/<newName>, it is done for you.
The root folder of the repository can then be rename if you want (but it does not matter for Git)

Related

Changing GitHub Account Swift Project

I would like to change a swift project from one GitHub account to another account. I want to commit the project to another account but I get an error - I assume I need to remove the .git file from the project but the answer here is not working for me.
Why do that?? No, all you have to do is define the new repo, push to it, then remove the other one. Each Git repo is on a local machine. That repository can be synced with one or more remote repositories. Right now, you probably have GitHub (account 1) setup as origin (a remote). What I would do is:
rename origin to oldrepo or something
create origin with the new url
push to it
Then you can remove the old one.
To edit your remotes, you can either do commands:
git remote remove origin, get remote add origin <newUrl>
or you can edit the .git/config file with an editor.
Git: Working with Remotes

How can collaborators push their changes to my repo in GitHub

First I have created one project in Eclipse and committed to my GitHub using below commands:git init
git add .
git commit -m "first commit"
git remote add origin URI of my repo
git push -u origin master
Then I modified one file in Eclipse and committed to GitHub from Eclipse through creating remote and giving the remote URI of the repo.
I added my team member through add collaborator.
Then he downloaded my project and made a change in a file in Eclipse.
Now, how can he push that modified file to my GitHub repository from within Eclipse?
We have done one thing. He created a remote and gave the URI of my repo. But still we are unable to commit that file.
You need to add your colleague as a collaborator. This can be done in the desired GitHub repo via Settings > Collaborators (you need to type in your password again). Afterwards they have those permissions.
UPDATE
Sorry and good morning ;)
I overlooked that you already added your partner as a collaborator. Another possible reason for your situation could be in the Temporary interaction limits where you can, amongst others, limit the interaction with your repo to prior contributors.
If that doesn't help. Please add some more informations about your colleague's git logs.
UPDATE 2
#Rahul K regarding your comment (which you better add to your question, for faster recognition), your colleague first needs to integrate the remote changes via git pull origin master in order to be able to push his or her changes afterwards. But be aware that he or she might need to migrate any conflicts to files both of you applied changes to.
Best regards, David
I have resolved the issue by cloning the repo in my local folder, adding the project to eclipse and changing the file committed.
Before that you have to add that person as a collaborator. So that he/she can clone your repo using the command below:
git clone "Path to the repository"
This is an old question but I'll like to say this to help others that might still be facing this same issue.
I also faced this issue with a friend. I already made him a collaborator but he couldn't push. What we did to solve it was to clone the repo using the ssh url instead. Then we set up authentication in git with ssh. And we were able push successfully.
If you already cloned the repo with the usual HTTPS url, you can change the remote origin url using the git remote set-url origin <url> command but url here will be the ssh url.

Cancelling Version Control in Xamarin Studio while sharing with Github

initially i was trying to commit a project to github , then accidentally i didn't commit the project well, now am trying to remove Version Control and switch it again to Commit the project to Github.
I want to see this :
But am seeing this :
How can i Commit again , to github?
I recently just had this problem and asked the wonderful people at Github.
Note: I reset up a new repository, to commit to. I deleted the old one I had messed up. But still could not use Xamarin to Publish. Even after changing the remote connection in version control to the new repository.
This was the solution they provided me with:
From Github
I'm not familiar with the tool that your using to push to the repository but I can help you do this via the command line if that works for you?
Once we get the project pushed to GitHub I think should be able to clone it again to a fresh location on your computer and then link this into Xamarin hopefully.
The steps to push this from the command line would be:
Open the Terminal app and change directories to the location of the project on your local computer.
The command to change directories would be cd <full path to the projects location>. For example if your project was located in your documents folder
cd ~/Documents/projectname
Once there, you need to initiate the project for git version control, commit the project and link up the GitHub repository. To do that you can run the following commands one after the other:
git init
git add .
git commit -m `First commit`
git add remote origin https://github.com/yourrepository/project.git
The last step would be pushing to GitHub:
git push origin master
We have a help doc that has some instructions for this below:
https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
Let me know if you run into any trouble with that!
The only thing they did not mention was that you will be prompted for a username and password. This is the username and password for Github (not the token created for the repository)
Also in the linked documentation, in the above they use:
git push -u origin master
as the last step, I got an error when I did not include the -u
I also did not need to clone it.
The remote connection in Xamarin now links to this new repository. I have made and committed some changes to check.

Un-fork GitHub project into new GitHub project not associated with the original [duplicate]

How can I make GitHub forget or disassociate that my repo was originally a fork of another project?
I forked a project in GitHub. I can now see "forked from whatever/whatever". The parent repository "whatever/whatever" is no longer maintained. I have been allowed to continue use of the code base of the original repository to create an independent repository.
Is there a way to detach my project from the original repository?
Update Jan 2022:
Use the GitHub chatbot-virtual-assistant at https://support.github.com/contact?tags=rr-forks&subject=Detach%20Fork&flow=detach_fork
First answer:
You can contact github support and ask them to switch your repository to "normal mode".
On this page, "Commit was made in a fork" paragraph, it is explained that one has to go through support to switch. Therefore, it is likely that there is no way to do that by yourself (unless you destroy and recreate your repo which is explained before... if you do so be careful if you have tickets or a wiki attached to your project as they will be deleted!).
You could duplicate the forked repository to a new repository (without the fork dependency) from the GitHub UI, then remove the original forked one:
Sign in to GitHub
Select the + sign in the top right corner and select Import repository.
Import your forked repository. The new repository won't have the fork dependency.
Delete the original, forked repository in the repository settings.
NOTE: This approach will not preserve issues and pull requests.
Make sure you have all the important branches and tags on your local repo, delete the github repo, recreate the repository through usual means (no forking) and push the local repository back with git push --all. Note that if you have local branches that you don't want to publish, might be worth to create a temporary clean local clone for the operation.
However, this will also get rid of wiki and issues. As the wiki is in fact it's own repository, it can be handled similarly by cloning it and then recreating and pushing. The repo address is on wiki's Git Access page (git#github.com:user/repo.wiki.git).
This leaves issues. They can be exported through the API, but as far as I know, you can only create issues and comments with your person, so importing them perfectly is impossible.
So, if you need issues to be preserved, you should go through github support as Thomas Moulard suggests.
I got the similar problem, and ended up using this github help page to solve it. I didn't mind about the wiki and issues tracker as it was for my blog using a theme kindly developed by another user.
To detach a forked repo and use it as your own after several commits without losing the whole history:
git clone --bare git#github.com:user/forked_repo.git
Create a new empty reposity new-repository on the github website.
And push a mirrored version:
cd user.github.com.git/
git push --mirror git#github.com:user/new-repository.git
One can rename on github, the forked_repository with another name to keep it as backup and check updates if needed. Or simply delete it.
Renaming the new-repository to the original name does the job. As a side effect, your commits now appear in your history.
Log in to GitHub with your credentials.
Go to https://support.github.com/contact?tags=rr-forks&subject=Detach%20Fork&flow=detach_fork.
Choose "Detach", then enter the URL or repo name of the fork as your-user-name/repository-name, and answer the other questions of the virtual assistant.
You will get an email with a ticket number where you can check the status of your request. You will also be notified per email once your repo has been deforked.
Most repository settings will stay unchanged, including user permissions, stargazers, issues, PRs, discussions, etc.
Using the info from aurelien and Clayton, I was able to do this with the following:
$ git clone --bare https://github.com/my/forked_repo.git
<delete forked_repo on GitHub>
<recreate repo on GitHub using same name>
$ cd forked_repo.git
$ git push --mirror
Here's the documentation for git clone --bare:
Make a bare Git repository. That is, instead of creating <directory> and placing the administrative files in <directory>/.git, make the <directory> itself the $GIT_DIR. This obviously implies the -n because there is nowhere to check out the working tree. Also the branch heads at the remote are copied directly to corresponding local branch heads, without mapping them to refs/remotes/origin/. When this option is used, neither remote-tracking branches nor the related configuration variables are created.
Here's the documentation for git push --mirror:
Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end. This is the default if the configuration option remote.<remote>.mirror is set.
Note: like the other git based answers, this will not copy over issues that are not part of the git repo such as the wiki and issues. Per Tapio:
The wiki is a separate git repo and can be handled in a similar fashion per Tapio. The address is: git#github.com:user/repo.wiki.git.
Issues can be exported via the GitHub API but there are issues recreating them since they can only be created by your user, so imports will lose information.
This only applies to GitHub Enterprise, not on github.com
Logged in to an account that has admin privileges:
Go to the repository that you need to detach: https://<ghe url>/<org>/<repo>
Click on the “Site Admin” rocket on the top right corner
Click "Collaboration" on the top menu bar
Click on “Network” on the left pane
Click on “Make Root” in the Network Structure pane
Accept
This was tested on GitHub Enterprise 2.9
If you do not need any past commits (I didn't in my case), you can just:
fork the project
make a local copy of the fork (I used my IDE to do that)
delete the git folder from your local copy
commit the project as you normally would a new project.
You can just delete the fork from your github account after. Took me all of one minute and worked like a charm.

What does it mean "to fetch" before I can push?

I uploaded my whole project on my repository of github yesterday.
I'd like to update the online version today, and when I use git push -u origin masterorder, the bash window says:
! [rejected] master -> master (fetch first)
So how do I "fetch"?
If I use git pull first, would my local files be overwritten by the online version?
So how do I "fetch"?
By using the command:
git fetch
Basically, your local repo is out of sync with the remote (Github) repository. If you have multiple remote repos, you can specify which one, and you can also specify which branch. Try
git help fetch
for a complete description of the command and the various parameters you can pass in.
If I use git pull first, would my local files be overwritten by the online version?
git pull is like doing a git fetch followed by git merge -- that is, it gets the updates from the remote and attempts to merge those into your local files. That may be fine, or not, depending on what you intend. Read the help for both commands so that you can make an informed decision.