github fork confusion - github

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?".

Related

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

How to create a second distinct pull request from a GitHub fork?

I have a GitHub fork. I used it to create a pull request against upstream.
I'm trying to work on a second pull request. I don't want the second pull request to cross pollinate into the first pull request.
How do I configure things so I can work on the second pull request without contaminating the first full request?
The obvious answer (for me) is to create a second clone. GitHub does not allow that.
The next obvious answer (for me) is to create a branch. But Git does not allow me to configure it. I'm not allowed to create a branch and set its origin to my GitHub clone.
Here's the error when attempting to create a branch. Notice the pull fails, and I am not allowed to set its origin to my fork:
$ git checkout -b arm-aes
Switched to a new branch 'arm-aes'
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=<remote>/<branch> arm-aes
Now try to fix it:
$ git remote -v
origin https://github.com/noloader/botan.git (fetch)
origin https://github.com/noloader/botan.git (push)
upstream https://github.com/randombit/botan (fetch)
upstream https://github.com/randombit/botan (push)
$ git branch --set-upstream-to=https://github.com/noloader/botan.git
error: the requested upstream branch 'https://github.com/noloader/botan.git' does not exist
...
$ git branch --set-upstream-to=https://github.com/noloader/botan
error: the requested upstream branch 'https://github.com/noloader/botan' does not exist
...
But Git does not allow me to configure it. I'm not allowed to create a branch and set its origin to my GitHub clone.
Sure it does:
git fetch upstream
git checkout -b newbranch upstream/master
Make sure you have a git remote upstream referencing the original repository (the one you have forked).
git remote add upstream https://github.com/<user>/<repo>

Fork a github repo and push to my private repo

I am taking a class which has a classwide github repo to publish labs, docs, etc. I want to fork this, do my own work on the labs, and push to my private git repo. However, I still want to be able to pull changes from the class github. Is there a way to do this?
Thanks
set up two remote branches, one for your private and one to the class
git remote add classwide sshblah
git remote add private sshblah
then you can
git fetch classwide
to grab your class stuff and
git merge localbranch
to work on it, then you can
git push localbranch private
to put it into your private repo
Yes, for sure, the key is in your repo remotes, so your fork have a remote called "origin" and for the original repo create a remote called upstream.
create the upstream remote with following command
git remote add upstream https://github.com/user/original.git
Then validate your remotes
git remote -v
origin https://github.com/your-user/fork.git (fetch)
origin https://github.com/your-user/fork.git (push)
upstream https://github.com/user/original.git (fetch)
upstream https://github.com/user/original.git (push)
So now you can push and pull from the original repo
git pull upstream branch
git push upstream branch
In the other way you can create a pull request directly in Github

fatal error in git hub when pushing in branch

I want to push to a branch which is not master. That is what I did:
git init
git add .
git commit -m "first"
git push origin second (second is the name of a branch) but it say
fatal: origin does not appear to be a git repository.
fatal: could not read from remote repository.
Please sure you have the correct access rights and the repository exists.
Last night I could do that and in the morning suddenly it does not recognize my branch! it does not show my branch when I do git branch, it only shows a master branch. But why I experience this problem sometimes?
Thanks :)
First, make sure you are in the right branch: if git branch doesn't list 'second', you can create it:
git checkout -b second
Actually "second" branch exists and I can see it on the github site
Then:
git checkout -b second --track origin/second
(a git fetch origin might be in order first)
Then, make sure the remote 'origin' exists:
git remote -v
And then, push and set origin/second as upstream branch of your local branch second.
git push -u origin second
(See "Why do I need to explicitly push a new branch?" for more)
try
git pull origin master
before
git push origin master
I had the same error and it worked for me.

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

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".