How do I change the remote source of my github repo? - github

I forked a repo and set everything up on my local machine. However, when I do 'git remote -v' it shows the original repo as my fetch and push source. I want it to by from my forked repo. How do I change it over to that without starting all over? And then, how do I add an upstream to the original repo?

From the git remote man page:
git remote set-url origin https://github.com/user/forkname
git remote add upstream https://github.com/maintainer/reponame
See also the examples of GitHub: Changing a remote's URL.
set-url
Changes URL remote points to.
You will then be able to fetch from upstream, and push to origin:
See "What is the difference between origin and upstream in Github".

Related

Cannot update sourcecode from remote repository to local repository

I try to update source code from remote repository to local repository by git command:
$git pull origin dev
The terminal has noticed:
From https://github.com/AAA/BBB
* branch dev -> FETCH_HEAD
Already up to date.
But the source code was not updated.
How can I solve this problem?
Have you tried confirming the git remote -v and see if it points to the right origin ?
Otherwise set the remote origin by
git remote set-url origin <remote-repo-url>

Unable to push files in git repository

I am trying to push my files using git bash to online git repository using this command.
$ git push -u origin master https://github.com/SMAmmar/git-test.git
But after using it i am getting this error
fatal: invalid refspec 'https://github.com/SMAmmar/git-test.git'
How can I solve this problem? I am a newbie when using github so please elaborate what you guys are telling me to do.
From git push
git push <repository> [<refspec>…]
The "remote" repository that is destination of a push operation.
This parameter can be either a URL (see the section GIT URLS below) or the name of a remote (see the section REMOTES below).
So yes, git push can take a URL
But the order is important:
where you push (the URL or remote name)
what you push
In your case:
git push -u origin master
git push -u https://github.com/SMAmmar/git-test.git master
But not both origin and https://github.com/SMAmmar/git-test.git
The first form is preferred. Once that first command is working, a simple git push will be enough.
git push doesn't take a URL. Instead it takes the name of a remote repository that you've previously set up, that's origin, and a branch to push. origin is automatically set up when you git clone a repository.
If you run git remote -v you should see something like this:
origin https://github.com/SMAmmar/git-test.git (fetch)
origin https://github.com/SMAmmar/git-test.git (push)
If you see some other URL, use git remote set-url origin https://github.com/SMAmmar/git-test.git to make origin point at that URL.
Then git push origin master says to push your master branch to the master branch on the repository identified by origin which is https://github.com/SMAmmar/git-test.git.
See also
Working With Remotes
Managing Remote Repositories

Error While commiting to Github

remote: Repository not found.
fatal: repository 'https://github.com/vivekghanchi/portfolio.git/' not found
You need first to create your repository in GitHub (it's done directly in your Web browser). Then you can do a git push to upload your local commits to the new repository.
Also, after creating your GitHub repository, make sure the url you are pushing to matches that of GitHub, I notice an extra / at the end of your url, which should not be there.
To see the url you are pushing to, issue:
git remote -v
the repository is deleted but I was committing to a new repository after than also it is showing this
Committing is a local operation.
Make sure your remote url matches the one of your new repo.
Update it with:
cd /path/to/my/local/repo
git remote set-url https://github.com/vivekghanchi/aNewRepo
Then try to push again:
git push
Pushing is not "committing to GitHub", but rather "publishing your local commits to your upstream GitHub repository".
You need first to create your repository in GitHub (it's done directly in your Web browser). Then you can do a git push to upload your local commits to the new repository.
Committing is a local operation.
or your can add already existing repo
git remote add origin remote repository URL

github fork confusion

I followed this https://help.github.com/articles/fork-a-repo post to clone a repository locally. After doing that another developer created a branch to the main repository and added some features to that branch. My question is
How do I get that branch into my fork.
Can I get that missing branch again to my local using git pull upstream/missing_branch command?
Thank you
You need to add a remote repo 'upstream' in the local repo (which has for origin your fork)
(git remote man page)
git remote add upstream url://upstream/repo
The OP opensourcelover mentions seeing this:
git remote -v,
origin git#github.com:username/project.git (fetch)
origin git#github.com:username/project.git (push)
upstream git#github.com:username/project.git (fetch)
upstream git#github.com:username/project.git (push)
If your origin is the same as your upstream remote repo, you can replace that url by the https one for that upstream:
git remote set-url upstream https://github.com/originalDevName/originalRepoName
That way, you can git fetch upstream and get the new branch.
If you need to work on that new branch, you can now declare it:
git branch -u upstream/foo foo
See "How do you make an existing Git branch track a remote branch?".

How to update forked repo from GitHub Web?

I want to update a forked repo from GitHub web interface.
I tried a few things from other questions but it gave me fatal: not a git repo when I use git remote add upstream git://blabla
Try using an https address first, as mentioned in GitHub FAQ:
git remote add upstream https://github.com/octocat/Spoon-Knife.git
# if upstream already exist
git remote set-url upstream https://github.com/octocat/Spoon-Knife.git
And make sure of the case used in this address (it is case-sensitive, and the slightest error will give you "not a git repo").