Run the git remote set-url --add --push origin git-repository-name command where git-repository-name is the URL and name of the Git repository where you want to host your code. This changes the push destination of origin to that Git repository.
origin master is the branch master on the remote origin . So we have these: origin/master ( A representation or a pointer to the remote branch) master - (actual branch)
You can view that origin with the command git remote -v, which will list the URL of the remote repo.
'git pull origin master' will fetch and update only a specific branch called master and origin in the remote repository. Often, the default branch in Git is a master branch, and it keeps updating frequently. A user can use any branch name to pull that branch from the remote.
I came to this question looking for an explanation about what the message "your branch is ahead by..." means, in the general scheme of git. There was no answer to that here, but since this question currently shows up at the top of Google when you search for the phrase "Your branch is ahead of 'origin/master'", and I have since figured out what the message really means, I thought I'd post the info here.
So, being a git newbie, I can see that the answer I needed was a distinctly newbie answer. Specifically, what the "your branch is ahead by..." phrase means is that there are files you've added and committed to your local repository, but have never pushed to the origin. The intent of this message is further obfuscated by the fact that "git diff", at least for me, showed no differences. It wasn't until I ran "git diff origin/master" that I was told that there were differences between my local repository, and the remote master.
So, to be clear:
"your branch is ahead by..." => You need to push to the remote master. Run "git diff origin/master" to see what the differences are between your local repository and the remote master repository.
Hope this helps other newbies.
(Also, I recognize that there are configuration subtleties that may partially invalidate this solution, such as the fact that the master may not actually be "remote", and that "origin" is a reconfigurable name used by convention, etc. But newbies do not care about that sort of thing. We want simple, straightforward answers. We can read about the subtleties later, once we've solved the pressing problem.)
Earl
1.
Find out where Git thinks 'origin/master' is usinggit-remote
git remote show origin
..which will return something like..
* remote origin
URL: [email protected]:~/something.git
Remote branch merged with 'git pull' while on branch master
master
Tracked remote branch
master
A remote is basically a link to a remote repository. When you do..
git remote add unfuddle [email protected]/myrepo.git
git push unfuddle
..git will push changes to that address you added. It's like a bookmark, for remote repositories.
When you run git status
, it checks if the remote is missing commits (compared to your local repository), and if so, by how many commits. If you push all your changes to "origin", both will be in sync, so you wont get that message.
2.
If it's somewhere else, how do I turn my laptop into the 'origin/master'?
There is no point in doing this. Say "origin" is renamed to "laptop" - you never want to do git push laptop
from your laptop.
If you want to remove the origin remote, you do..
git remote rm origin
This wont delete anything (in terms of file-content/revisions-history). This will stop the "your branch is ahead by.." message, as it will no longer compare your repository with the remote (because it's gone!)
One thing to remember is that there is nothing special about origin
, it's just a default name git uses.
Git does use origin
by default when you do things like git push
or git pull
. So, if you have a remote you use a lot (Unfuddle, in your case), I would recommend adding unfuddle as "origin":
git remote rm origin
git remote add origin [email protected]:subdomain/abbreviation.git
or do the above in one command using set-url:
git remote set-url origin [email protected]:subdomain/abbreviation.git
Then you can simply do git push
or git pull
to update, instead of git push unfuddle master
I had a problem that was similar to this where my working directory was ahead of origin by X commits
but the git pull
was resulting in Everything up-to-date
. I did manage to fix it by following this advice. I'm posting this here in case it helps someone else with a similar problem.
The basic fix is as follows:
$ git push {remote} {localbranch}:{remotebranch}
Where the words in brackets should be replaced by your remote name, your local branch name and your remote branch name. e.g.
$ git push origin master:master
sometimes there's a difference between the local cached version of origin master (origin/master) and the true origin master.
If you run git remote update
this will resynch origin master with origin/master
see the accepted answer to this question
Differences between git pull origin master & git pull origin/master
I thought my laptop was the origin…
That’s kind of nonsensical: origin
refers to the default remote repository – the one you usually fetch/pull other people’s changes from.
How can I:
git remote -v
will show you what origin
is; origin/master
is your “bookmark” for the last known state of the master
branch of the origin
repository, and your own master
is a tracking branch for origin/master
. This is all as it should be.
You don’t. At least it makes no sense for a repository to be the default remote repository for itself.
It isn’t. It’s merely telling you that you have made so-and-so many commits locally which aren’t in the remote repository (according to the last known state of that repository).
[ Solution ]
$ git push origin
^ this solved it for me. What it did, it synchronized my master (on laptop) with "origin" that's on the remote server.
I am struggling with this problem and none of the previous answers tackle the question as I see it. I have stripped the problem back down to its basics to see if I can make my problem clear.
I create a new repository (rep1), put one file in it and commit it.
mkdir rep1
cd rep1
git init
echo "Line1" > README
git add README
git commit -m "Commit 1"
I create a clone of rep1 and call it rep2. I look inside rep2 and see the file is correct.
cd ~
git clone ~/rep1 rep2
cat ~/rep2/README
In rep1 I make a single change to the file and commit it. Then in rep1 I create a remote to point to rep2 and push the changes.
cd ~/rep1
<change file and commit>
git remote add rep2 ~/rep2
git push rep2 master
Now when I go into rep2 and do a 'git status' I get told I am ahead of origin.
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: README
#
README in rep2 is as it was originally, before the second commit. The only modifications I have done are to rep1 and all I wanted to do was push them out to rep2. What is it I am not grasping?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With