How to push unsynced commits to GitHub? - github

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.

Related

VS 2017 Team Explorer GIT "Push Branch" Grayed out

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.

Github with eclipse error [duplicate]

I am getting this message while pushing to github repository. Can you tell me step by step procedure to fix it? I pushed only once and it was successful. But, when I updated a project and tried to push my second commit, it shows "master rejected non-fast-forward" and does not allow me to push. Please explain the procedure.
I had this same problem and I was able to fix it. afk5min was right, the problem is the branch that you pulled code from has since changed on the remote repository. Per the standard git practices(http://git-scm.com/book/en/Git-Basics-Working-with-Remotes), you need to (now) merge those changes at the remote repository into your local changes before you can commit. This makes sense, this forces you to take other's changes and merge them into your code, ensuring that your code continues to function with the other changes in place.
Anyway, on to the steps.
Configure the 'fetch' to fetch the branch you originally pulled from.
Fetch the remote branch.
Merge that remote branch onto your local branch.
Commit the (merge) change in your local repo.
Push the change to the remote repo.
In detail...
In eclipse, open the view 'Git Repositories'.
Ensure you see your local repository and can see the remote repository as a subfolder. In my version, it's called Remotes, and then I can see the remote project within that.
Look for the green arrow pointing to the left, this is the 'fetch' arrow. Right click and select 'Configure Fetch'.
You should see the URI, ensure that it points to the remote repository.
Look in the ref mappings section of the pop-up. Mine was empty. This will indicate which remote references you want to fetch. Click 'Add'.
Type in the branch name you need to fetch from the remote repository. Mine was 'master' (btw, a dropdown here would be great!!, for now, you have to type it). Continue through the pop-up, eventually clicking 'Finish'.
Click 'Save and Fetch'. This will fetch that remote reference.
Look in the 'Branches' folder of your local repository. You should now see that remote branch in the remote folder. Again, I see 'master'.
Right-Click on the local branch in the 'Local' folder of 'Branches', which is named 'master'. Select 'Merge', and then select the remote branch, which is named 'origin/master'.
Process through the merge.
Commit any changes to your local repository.
Push your changes to the remote repository.
Go have a tasty beverage, congratulating yourself. Take the rest of the day off.
In my case I chose the Force Update checkbox while pushing. It worked like a charm.
In the meantime (while you were updating your project), other commits have been made to the 'master' branch. Therefore, you must pull those changes first to be able to push your changes.
Applicable for Eclipse Luna + Eclipse Git 3.6.1
I,
cloned git repository
made some changes in source code
staged changes from Git Staging View
finally, commit and Push!
And I faced this issue with EGit and here is how I fixed it..
Yes, someone committed the changes before I commit my changes. So the changes are rejected.
After this error, the changes gets actually committed to local repository.
I did not want to just Pull the changes because I wanted to maintain linear history as pointed out in - In what cases could `git pull` be harmful?
So, I executed following steps
from Git Repository perspective, right click on the concerned Git
project
select Fetch from Upstream - it fetches remote updates (refs and objects) but no updates are made locally. for more info refer What is the difference between 'git pull' and 'git fetch'?
select Rebase... - this open a popup, click on Preserve merges during rebase see why
What exactly does git's "rebase --preserve-merges" do (and why?)
click on Rebase button
if there is/are a conflict(s), go to step 6 else step 11
a Rebase Result popup would appear, just click on OK
file comparator would open up, you need to modify left side file.
once you are done with merging changes correctly, goto Git Staging view
stage the changes. i.e. add to index
on the same view, click on Rebase-> Continue. repeat 7 to 10 until all conflicts are resolved.
from History view, select your commit row and select Push Commit
select Rebase Commits of local....... checkbox and click next. refer why - Git: rebase onto development branch from upstream
click on Finish
Note: if you have multiple local repository commits, you need to squash them in one commit to avoid multiple merges.
Configure
After pushing the code when you get a rejected message, click on configure and click Add spec as shown in this picture
Drop down and click on the ref/heads/yourbranchname and click on Add Spec again
Make sure you select the force update
Finally save and push the code to the repo
Open git view :
1- select your project and choose merge
2- Select remote tracking
3- click ok
Git will merge the remote branch with local repository
4- then push
This error means that remote repository has had other commits and has paced ahead of your local branch.
I try doing a git pull followed by a git push. If their are No conflicting changes, git pull gets the latest code to my local branch while keeping my changes intact.
Then a git push pushes my changes to the master branch.
In my case i forgot to pull the new changes from git
Right click on the project Fetch From Upstream
Right click on the project Pull
Right click on the project Push to Upstream
I have found that you must be on the latest commit of the git.
So these are the steps to take:
1) make sure you have not been working on the same files, otherwise you will run into a DITY_WORK_TREE error.
2) pull the latest changes.
3) commit your updates.
Hope this helps.
Go in Github an create a repo for your new code.
Use the new https or ssh url in Eclise when you are doing the push to upstream;

Can't checkout remote branch using GitHub Desktop

When I first clone a repo using GitHub Desktop (windows version), I'm able to see all of the branches and can checkout the branches.
However, if another contributor creates a new remote branch (after I've done the clone), GitHub Desktop isn't able to fetch and checkout the new branches. The branches are visible via the GitHub website. The only way I've found to checkout these branches via GitHub desktop is to delete the local repo and clone again. I was expecting the "Sync" button to handle fetching new branches from the remote repo.
Any ideas?
According to Steve Ward at GitHub Support:
You should be able to hit F5 in GitHub Desktop to refresh the repository and fetch any new branches from the remote repository. There currently aren't any animations for this process, but it should work without issue. [...] we automatically fetch new branches every five minutes as well.
You can also click on the "Gear" button in upper right of the client, select "Open in Git Shell" and type the command git fetch in the command window that is opened...

How can someone using egit/eclipse pull a remote branch that I created without using command line?

This is probably quite simple, but I am just not familiar with eclipse. I have a dev branch that I have pushed to the server for review using the basic git push origin dev. My co-worker is new to git and would prefer to stay within eclipse to review the code. He has egit installed and I cannot seem to find a way to pull a specific remote branch. I know this is brief but I am more than willing to provide any information for clarification.
To easily review the changes, your co-worker can check out the remote branch as a new local branch and then look at the code and commits.
One possible way is:
Team > Fetch from Upstream to get the newest branches (or a normal pull, which includes a fetch)
Team > Switch to > New Branch...
Select origin/dev (assuming the remote is named origin) as the base branch
Click Finish to check out the new local dev branch
It can also be done via the Git Repositories view by expanding Branches > Remote Tracking and using Create Branch... from the context menu.
Another way is to find the branch in the History view (you may need to toggle the Show All Branches and Tags option, see here) and use Create Branch... there.

Egit rejected non-fast-forward

I am getting this message while pushing to github repository. Can you tell me step by step procedure to fix it? I pushed only once and it was successful. But, when I updated a project and tried to push my second commit, it shows "master rejected non-fast-forward" and does not allow me to push. Please explain the procedure.
I had this same problem and I was able to fix it. afk5min was right, the problem is the branch that you pulled code from has since changed on the remote repository. Per the standard git practices(http://git-scm.com/book/en/Git-Basics-Working-with-Remotes), you need to (now) merge those changes at the remote repository into your local changes before you can commit. This makes sense, this forces you to take other's changes and merge them into your code, ensuring that your code continues to function with the other changes in place.
Anyway, on to the steps.
Configure the 'fetch' to fetch the branch you originally pulled from.
Fetch the remote branch.
Merge that remote branch onto your local branch.
Commit the (merge) change in your local repo.
Push the change to the remote repo.
In detail...
In eclipse, open the view 'Git Repositories'.
Ensure you see your local repository and can see the remote repository as a subfolder. In my version, it's called Remotes, and then I can see the remote project within that.
Look for the green arrow pointing to the left, this is the 'fetch' arrow. Right click and select 'Configure Fetch'.
You should see the URI, ensure that it points to the remote repository.
Look in the ref mappings section of the pop-up. Mine was empty. This will indicate which remote references you want to fetch. Click 'Add'.
Type in the branch name you need to fetch from the remote repository. Mine was 'master' (btw, a dropdown here would be great!!, for now, you have to type it). Continue through the pop-up, eventually clicking 'Finish'.
Click 'Save and Fetch'. This will fetch that remote reference.
Look in the 'Branches' folder of your local repository. You should now see that remote branch in the remote folder. Again, I see 'master'.
Right-Click on the local branch in the 'Local' folder of 'Branches', which is named 'master'. Select 'Merge', and then select the remote branch, which is named 'origin/master'.
Process through the merge.
Commit any changes to your local repository.
Push your changes to the remote repository.
Go have a tasty beverage, congratulating yourself. Take the rest of the day off.
In my case I chose the Force Update checkbox while pushing. It worked like a charm.
In the meantime (while you were updating your project), other commits have been made to the 'master' branch. Therefore, you must pull those changes first to be able to push your changes.
Applicable for Eclipse Luna + Eclipse Git 3.6.1
I,
cloned git repository
made some changes in source code
staged changes from Git Staging View
finally, commit and Push!
And I faced this issue with EGit and here is how I fixed it..
Yes, someone committed the changes before I commit my changes. So the changes are rejected.
After this error, the changes gets actually committed to local repository.
I did not want to just Pull the changes because I wanted to maintain linear history as pointed out in - In what cases could `git pull` be harmful?
So, I executed following steps
from Git Repository perspective, right click on the concerned Git
project
select Fetch from Upstream - it fetches remote updates (refs and objects) but no updates are made locally. for more info refer What is the difference between 'git pull' and 'git fetch'?
select Rebase... - this open a popup, click on Preserve merges during rebase see why
What exactly does git's "rebase --preserve-merges" do (and why?)
click on Rebase button
if there is/are a conflict(s), go to step 6 else step 11
a Rebase Result popup would appear, just click on OK
file comparator would open up, you need to modify left side file.
once you are done with merging changes correctly, goto Git Staging view
stage the changes. i.e. add to index
on the same view, click on Rebase-> Continue. repeat 7 to 10 until all conflicts are resolved.
from History view, select your commit row and select Push Commit
select Rebase Commits of local....... checkbox and click next. refer why - Git: rebase onto development branch from upstream
click on Finish
Note: if you have multiple local repository commits, you need to squash them in one commit to avoid multiple merges.
Configure
After pushing the code when you get a rejected message, click on configure and click Add spec as shown in this picture
Drop down and click on the ref/heads/yourbranchname and click on Add Spec again
Make sure you select the force update
Finally save and push the code to the repo
Open git view :
1- select your project and choose merge
2- Select remote tracking
3- click ok
Git will merge the remote branch with local repository
4- then push
This error means that remote repository has had other commits and has paced ahead of your local branch.
I try doing a git pull followed by a git push. If their are No conflicting changes, git pull gets the latest code to my local branch while keeping my changes intact.
Then a git push pushes my changes to the master branch.
In my case i forgot to pull the new changes from git
Right click on the project Fetch From Upstream
Right click on the project Pull
Right click on the project Push to Upstream
I have found that you must be on the latest commit of the git.
So these are the steps to take:
1) make sure you have not been working on the same files, otherwise you will run into a DITY_WORK_TREE error.
2) pull the latest changes.
3) commit your updates.
Hope this helps.
Go in Github an create a repo for your new code.
Use the new https or ssh url in Eclise when you are doing the push to upstream;