VS 2017 Team Explorer GIT "Push Branch" is Grayed out for me. I create a new local branch from a remote branch with no tracking and then I try to create a remote branch with the same name as the local branch by clicking on "Push Branch". Why would this option be grayed out for me?
I place it here, as someone like me will search again for that, I have resolved by doing branch Rebase. Commit your changes before. And then:
Probably it happens after you have manipulated remote repository settings.
In another case i just deleted all origins and created them again
Another addition. Be sure that you always has remote with "origin" name, that's another problem I faced right now, during migration of my projects.
Rename one of your remotes to "origin" with this command:
git remote rename your-remote-name-goes-here origin
Then you should be able to Push, Pull, and Fetch in Visual Studio. These options will no longer be grayed out.
The direct way to push a new created local branch to VSTS git repo by VS is clicking push branch button directly on local branch (don’t need to create the same branch in remote manually).
Detail steps as: VS -> Team explorer -> Branches -> right click the local branch -> Push branch -> then the local branch is pushed to remote.
Since you have already created the same branch on remote, you can fetch first and then push:
Team explorer ->Sync -> Fetch -> push.
when you clone the remote repo (no matter on VSTS or bitbucket) again, and siwtch to the new created branch, the branch willexist in remotes/origin, so you can push directly.
Related
I have created a branch from atlassian jira and I can see the branch in the sourcetree, under branches. But when I am going to Eclipse -> Team -> Switch to -> Other -> Remote Tracking I can't see it anywhere.
When I also go to the command line and type
git branch -a
I don't see it
Did you make sure you fetched from remote after having created the new branch in JIRA?
If not, it would explain the remote branch not showing up in your branch -a log.
In that case, just git fetch and your local refs of remote branches will be updated.
(And then you'll be able to git checkout <your_new_branch> to create the local counterpart and set its upstream in one go)
I created an empty project in Git. I also created a Java EE projcet in Eclipse (note: Eclipse has the Git plug-in installed).
From within Eclipse, I accessed and duplicated the (empty) Git Repository project on my Local Machine (or rather laptop).
I then wrote some code in my Java EE project.
From within the project, I then used the Team -> Commit option on it to :
1) Add the project to the Local Repository
2) Commit and push the contents from the Local Repository to the Git Repository.
My problem is that all of this work was done using the Master branch.
The Git Repository is currently sitting on the Master branch.
The Local Repository is currently sitting on the Master branch.
Whenever I make changes to the project and do a Team-> Commit, all actions happen with the Master branches.
Master -> Master
What I would like to do is as follows:
1) create 3 more branches in Git Repository (called consolidation, testing, production) - each new branch would be a copy of the Master Branch
2) On the Eclipse side, I need to fix it so that when any changes are made and saved to the Local Repository, the data will be saved to the
Consolidation Branch of the Local Repository and ~NOT~ the Master Branch (which is what happens now).
3) After saving data in the Consolidation Branch, from then on out, when code is sent to the Git Repository, it would be done by using the Consolidation branch and NOT the Master branch.
How can I do this?
TIA
Update
#Howlger
Hi and thanks for the response! Your suggestion gave me a clue on how to solve the problem. First, I logged into Git and copied the Master branch to a "dev" branch.
Next, I switched to the Git perspective (locally) under Eclipse and created a "dev" branch for my project:
Branches -> Switch To -> New Branches
Then, I followed some of your advice except I created a path that would allow for
branch : dev (local) => branch : dev (remote)
It is under the "Advanced" button.
I did a small test and it worked. Thanks again!
Update
Hi again - just logging in to note that I changed the references so that
Source Ref = refs/heads/*
Target Ref = refs/heads/*
The mapping of a local branch to a branch of the remote/upstream repository is specified by the push ref mappings. It looks like your current push ref mapping is HEAD:refs/heads/master: your current local branch will be pushed to the remote/upstream repository master branch. To map local branches to the remote/upstream repository branches with the same name, just remove all push ref mappings:
In the Git Repositories view righ-click the Remotes > origin > push node and choose Configure Push...
Select the mapping and click Delete
Click Save
See EGit User Guide > Push Ref Specifications for more details.
I have a GitHub source control tool added to my copy of Visual Studio 2013 and when I right click on the solution and make a commit it says created the commit locally. When I try to sync the commit with the server, the sync button is greyed out.
My question is how do I set it up or what steps do I take so that the commit is pushed to the server?
It looks like you do not have the upstream remote / branch configured for this branch. Visual Studio operates as if the "push.default" configuration is set to "upstream".
If you go to the branches page, this branch should be listed under the "Unpublished" branches section. From that page, you can choose to "publish" this branch by right clicking on the unpublished branch and selecting publish in the resulting context menu. This will push the branch to the origin remote (with a branch of the same name as your local branch) and set the upstream tracking information for this branch. From then on, you can push and fetch from the Unsynced Commits page.
Here is a screen capture of where you need to go to publish an unpublished branch:
You need to add the online GitHub repo as a remote in your local git repo.
On the command line, that's git remote add origin <urL>; I don't know if the VS git UI exposes this.
We use Atlassian Stash but also found the Visual Studio UI a bit confusing at first. The sequence that works for us, using only the UI, is as follows:
First you have to add your "username" and e-mail address in the Git global settings via Team Explorer > Home > Git > Git Settings
On the "Solution Explorer" tab, right click on the solution and "Add Solution to Source Control" and choose Git.
On the "Team Explorer" tab, click on the repo you just created and go to branches
Choose the master branch, right click on it and choose "Publish" - you will be asked for the remote URL whereupon after you enter it, you will get a username/password prompt (for the remote server i.e. GitHub, Stash, etc.)
All this is doing is git push origin masterbut Microsoft chose to make it confusing by giving it another name.
Wait for the "publish" to be completed (there will be a file transfer status shown in the UI)
Once it is completed, go to the commits tab and you will see that all the options for Push/Pull/Fetch etc are available
Note: If you create another branch locally, you will have to push, er "publish", that one as well before the remote knows about it.
Final note: Visual Studio will not create projects and repos for you on the remote. You have to make sure the repo is setup on the remote before you can push a branch to it.
Weird issue: We found that if you try to push to a branch but fail (due to incorrect URL or a permissions issue) that we had to go back to the command prompt to "fix" the remote configuration for the repo/branch. This is using the standard git command:
git remote add origin https://myuser#stash.mycompany.com/scm/myproject/myrepo.git
After you publish a branch as in #jamill's answer you may run into this.
In Team Explorer, I was able to publish a branch, but then I could not do anything. Pull and Push were grayed out as shown:
So I did Actions > Open Command Prompt. Then Type:
git push origin My_Branch_Name
After doing this I could see the branch and my commit in my remote. (Github or whatever in your case). Also when running the command, the output said,
remote: Create pull request for My_Branch_Name:
If you want to keep this branch and merge it into master, then you can create a pull request on your remote. Otherwise as in my case I want to abandon the branch. You don't have to do anything.
I have a private repository on github.com and I want to pull it down to another development machine so that I can work with it in Eclipse but I am not sure exactly how to do it.
Do I have to create a local repository first or would that be created when the repository is pulled?
If you use git with eclipse, I assume you use eGit.
If you do, you can simply open File -> Import... -> Git -> Projects from Git -> Clone URI and from there everything should be clear to you. If it is not, just ask again and I will elaborate.
It will create a local repository for you if you chose so (later in the dialog you can chose something like import exisiting projects which is what you want if you already pushed your project to github once).
First, let's get eclipse out of the way. It has nothing to do with pulling/pushing to a remote repository.
The primary purpose of creating a remote repository is code collaboration. You can work on your local and then push to it. Others can pull from the remote and see your changes.
The primary way code collaboration is done in github is using the same model. To create a local branch out of a remote repository, you need to clone the repository. Cloning the repository would create a local master branch (the default branch) that will track the changes you make to your local repository. The other branch to note is the origin/master which tracks the changes you make to the remote repo.
When you want to make changes to the remote, you would need to perform three main steps:
Clone the existing repository: git clone https://github.com/johndoe/foo.git: this will create a local repository with the default master branch. You will work in this branch and when you have made the changes...
Commit the changes: git commit -m "this is the comment to identify my commit later"
Push it to the remote: git push origin master: origin refers to the remote repository; when you have cloned from the remote it is automatically called origin
So basically, you just need to clone the remote repository if you already have the remote on github. You don't need to create it separately.
You can import the project you have cloned into eclipse and work with it accordingly, then commit and push the changes to the remote.
Hope that helps.
I'm using Eclipse 4.2.1 and EGIT. I've done the following:
Created an account on Github.
Created a Repo and initialized it with a readMe from Github at the time I created it.
Cloned the repo using EGIT.
Created a Java project in Eclipse, a single class with a main method.
Share the project with GIT. Team-> Share Project-> GIT
In the Configure GIT repo dialog: Selected the repo I just cloned from Github.
Do a commit.
Push to remote origin.
Go back to Github and make a change to the readMe. (This shows in the commits on Github)
Fetch the changes with EGIT.
The changed readMe is shown in the remote tracking branch in EGIT but not in my local master branch. I tried refreshing but it still doesn't work. After doing this my local master is one behind and I can't push. I get rejected non-fast forward.
I can fix this by creating a new local branch based on HEAD then merging it into my local master. But why is this happening? Is anyone else experiencing this?
Fetching only gets the changes from github into the remote tracking branch (imagine this as a kind of index) on your local machine, but not into your working directory (the real files you edit). You still have to merge the remote changes into your local branch (which you can do by expanding the repository node Branches -> Remote Tracking -> origin/master and selecting "Merge" in the context menu).
If you always just want to fetch and immediately merge the remote changes, use the "Pull" command instead of the "Fetch" command, it is a combination of fetch and merge.