Reputation: 18754
During our project, we have always worked using a local ip address as origin. Now, we have moved to work on-site and need to push/pull using a remote ip.
Using manage remotes
, option I have saved the new ip as origin_remote
and trying to push my code there but for some reason I am getting this warning (or info message). I am not really sure if I am doing something wrong. Shouldn't the operation be smooth since I am just changing the ip and essentially pushing to the same repo ? Why is git telling me that it's a new branch ?
Upvotes: 3
Views: 2782
Reputation: 760
Other answers already covered why this is happening and explained that this is not a Git, but GitExtensions warning.
So I will suggest something to try to make the message go away. I tested it on two dummy repositories with Git Extensions 2.48.05 and git version 1.9.5.msysgit.0 on Windows 7. (Stack Overflow does not let me add screenshots at this moment.)
./git/config
from your repository (just in case)[branch "..."]
and [remote "..."]
sections, and save the file.Repository -> Remote repositories...
Name
put something you like, for example, origin_remote
Url
enter the URL you want to push to/pull fromSave changes
New remote
dialog will pop up
Do you want to automatically configure the default push and pull behavior for this remote?
Press Yes
. This should automatically add remote branch references and execute run git remote update
. Close the dialog and refresh Git Extensions to see the state of remote references in the repository graph (Browse) view. They should look like local branches, but the color is green and name format is origin_remote/your_branch_name
Now when you use Push
dialog in Remote
field choose origin_remote
. You should see no warning anymore.
In the end you should get something like this in ./git/config
in your local repository:
[remote "origin_remote"]
url = URL_TO_YOUR_REPOSITORY
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "your_branch_name"]
remote = origin_remote
merge = refs/heads/your_branch_name
[branch "your_other_branch_name"]
remote = origin_remote
merge = refs/heads/your_other_branch_name
Upvotes: 1
Reputation: 396
Although already correctly answered by VonC, just some additional details:
Git Extensions checks only the local config
file to make this wrong and quite problematic assumption.
A local repository can have more than one remotes but it can only have a single branch
section for each branch in the config
file, mapping the branch to a specific remote (it would not make sense to map the branch to more remotes anyway, since the branch
section is only used to simplify the push
and pull
commands, allowing you to omit the remote
and branch
arguments).
In a scenario (like ours), where more than one remotes are specified for a repository but of course the branch
section only maps to one of them, this warning appears every time you try to push to one of those secondary remotes. It's okay if you are used to it, but it becomes problematic for those who see it first time, as it immediately gives the idea that something wrong is about to happen that should probably be avoided.
The message itself, is confusing. The way it's put, gives the idea that Git Extensions has actually connected to the remote repository, went through it and found out that the branch does not exist there. But this is not the case and the branches already exist in the remote repository's /refs
. Git Extensions only checked the local config
file, therefore the message provides false information.
Normally Git Extensions should indeed connect to the remote repository, before showing such a message but even in this case, there's nothing wrong in pushing a new branch, just as a push
could also delete a branch in the remote repository, and in this case, since Git Extensions only checks the local config
file, you possibly do not get a warning at all, although it's more dangerous than adding one.
Upvotes: 0
Reputation: 1324737
This seems to be a Git Extension warning only (ie git alone wouldn't give you that same warning).
//Extra check if the branch is already known to the remote, give a warning when not.
//This is not possible when the remote is an URL, but this is ok since most users push to
//known remotes anyway.
if (TabControlTagBranch.SelectedTab == BranchTab && PushToRemote.Checked)
{
//If the current branch is not the default push, and not known by the remote
//(as far as we know since we are disconnected....)
if (RemoteBranch.Text != GetDefaultPushRemote(_NO_TRANSLATE_Remotes.Text) &&
!Module.GetHeads(true, true).Any(x => x.Remote == _NO_TRANSLATE_Remotes.Text && x.LocalName == RemoteBranch.Text) )
//Ask if this is really what the user wants
if (!Settings.DontConfirmPushNewBranch)
if (MessageBox.Show(owner, _branchNewForRemote.Text, _pushCaption.Text, MessageBoxButtons.YesNo) ==
DialogResult.No)
{
return false;
}
}
It depends how git extension did record the upstream branch:
Check with a command-line git command:
git config branch.master
See if branch.master.remote still points to the old ip address instead of the alias 'origin
', while git remote -v
does show origin
with the new ip address.
If though, re-record the upstream branch using remote name:
git config branch.master.remote origin
Upvotes: 0