Changing GitHub Account Swift Project - github

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

Related

Github New Project but using same existing project

I completed a project. We'll call it "A". I've pushed it to the master using
git push origin master .........."the final A version"
I have a customer who wants to use "A", but with their branding. Of course these have no association.
How does one handle that? I have created a new app on Github first called "B". Is that the correct first step?
What are the steps to establish a new project on github from my local clone without fear of destroying "A"?
Sounds like you want to fork your own project. In that case, you can simply make a local copy of your git repository and push it to a new github project.
Create a new github project, name it whatever
Make a copy of project A's directory on your computer, name it B.
In the local copy of your git project, (directory B), change git's remote URL to the new github URL.
git remote set-url <new-url>
where new-url is the new URL github tells you to push to when you created the new project.
Finally push your project to github git push origin master

Update a GitHub repository without cloning

Here's the situation, we are currently working on a project and lately we decided to upload it on GitHub. Now I made my changes and I want to push the changes onto the repository.
As far as I read, in order to make changes you need to clone the repository but that will download all files from the repository and I already have all of the source files.
I'm using GitHub desktop and I can't find any option to clone without downloading and update or create branches from my existing files. Creating a local one is an option but it needs to be uploaded as a separate repository instead of linking it to a current one.
Is there any way to push updates, create branches to the repository from my local project to an existing repository?
Your local project should already be a git repo, if you uploaded it to GitHub.
But in case it is not, switch to command-line, and do inside the root folder of your project (which should shows the same files as your remote repo):
git init .
git remote add origin https://github.com/<user>/<project>
git fetch
The fetch part will download the repo but leave your files alone.
(But do a backup still, just to be safe)
git branch master origin/master
git reset master
From there, your GitHub Desktop should show you any diff between your files and what was fetched from the repo.

Rename Github Repository

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)

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.

Getting started with GitHub and Eclipse (spring source toolsuite 2.7.1)

I am new with both Git and GitHub so please bear with me.
I have an empty repository on GitHub with an automatically created branch (gh-pages), which, I understand, is supposed to be used with GitHub's pages functionality.
Now what I would like to do is to create and eclipse project from which I could commit/push to this repository.
What is confusing me that I can't see any option to create a remote branch on github. I suppose pushing my source to gh-pages won't be a good idea. BTW, I also don't understand why the GitHub pages is feature is implemented as a branch? Aren't branches supposed to be merged with each other at some point. Clearly it wouldn't make any sense to merge github pages into my project. Wouldn't it be better to have a folder within my project for this purpose.
I googled and found this link but being a git noob I am not sure if that's what I want to do. I would like to use Eclipse as my primary interface to git and github only falling back to command line or other interfaces when there is no other option.
OK I think I have figured it out. Basically, what you need is to define a remote ref that need not exist before hand.
Create a project
Team->Share it to a local repository
In the repository view (Window->Show View-> Git -> Repositories) select the local repository and right click on remotes
Select new remote (configure push). Type origin in the remote name. Press OK
Change URL. Copy/paste the ssh uri from github. Select ssh protocol (make sure you have ssh key defined in eclipse SSH preferences, and uploaded to github)
Now the last part is to add Ref mapping. Click on Add.. in ref mapping section of screen. And enter refs/heads/master in both local and remote branches.
Or may be the refs/heads/master on both side isn't a good idea :)
I see, cloning a github repo that doesn't have gh-pages branch is simpler as it automatically creates this remote fetch spec
Remote Fetch Specification +refs/heads/*:refs/remotes/origin/*
Maybe this is what I need to enter in the step 6 above
Ok as it turned out the original idea of "refs/heads/master in both local and remote branch" was correct. Pushing with this configuration is showing my changes in git hub correctly. The second option on the other hand is failing silently.
Branches typically are used in the way you described, but nothing says they must be used that way. This is just the way github chose to let you manage your page content, and it works quite well. It's kind of similar to hosting multiple repos on one SVN server.
As for creating new repos, if you create a repo in github and then clone it, you'll have an empty repo locally that already points to github with a remote named "origin". This is a convenient way to start out, since you don't have to mess with adding a remote yourself. At this point, your repo has no commits and no branches in it. When you make the first commit, it will automatically establish a branch named "master". I don't know how eclipse is set up by default, but from the command line with default settings, you have to explicitly push new branches to a remote or else they won't get pushed at all. I.e. making the first commit and doing git push will just fail with a message like "No refs in common and none specified; doing nothing". Instead, you have to git push origin master to tell it to establish the "master" branch in remote "origin" (aka github). Thereafter, just a git push will work fine.
Hope that clears up some of your confusion.