Github with eclipse error [duplicate] - eclipse

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;

Related

Can't to push commits from local branch to github repository

I was committing and pushing in ordinary for my repository.
but once i used command of git checkout for change to the previous version of my repository.
after that i tried to commit and push, then it can not completed.
i try to use the --no-verify command to push the commit but it also not success.
error: failed to push some refs to 'https://github.com/ruwanliyanage123/Hair-4-U-Hospital.git'
i want to push my commit into github repository
Since you switched to a previous version of your repository, your head is most probably detached. You can't just go back anywhere in your history and make commits.
Consider making a branch from there and then commit to it.
Try to first check in which branch you are working do git branch, check is the one you are working. Then I sometimes do git pull to just make sure that the connection is working this should not delete your progress the you should be able to do git push. If you are afraid youll mess up first do a local back up of all project files except for the .git one which are hidden by default in windows.Lastly I would suggest never posting the actual link to your github repository in case whatever you are working is important, you can just replace with
https://github.com/user/projectname.git

How to push unsynced commits to 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.

Switch to another branch in EGit cannot work

I have Branch A and Branch B in the local branch folder.
Branch A is under working.
Now I want to switch to B.
The window pops out:
Checkout Conflicts
The files shown below have uncommitted changes which would be lost by checking out 'master'.
Either commit the changes, stash the changes, or discard the changes by resetting the current branch.
project.properties.
There are 3 options:
Commit..
Stash...
Reset
No matter which option I choose, it does not work.
For example, if I choose "Stash" option, it says:
"The repository does not contain any local changes to stash".
I suspect the egit records have some conflicts, so it cannot know how to do the next step.
The only way:
To remove the local branches, and clone the remote repository to the local?
This needs cost some time for downloading.
I had the same problem. EGit complaint about .class files which were not commited. I deleted the .class files and was able to switch to the desired branch without problems.
IMO removing local branch is not required.
I suggest first to pull the remote changes to local Branch A.
Resolve any conflicts while pulling the changes if any. Refer this video
Add your changes to Git staging area just by dragging the the files from unstaged area to staged area refer pic below.
Click on commit button, then push the changed to remote branch.
After doing this Branch A will be clean, then you can switch to Branch B just by double clicking on it or by right clicking on the repository node and selecting Switch to option in Git repository view.
Also I suggest to use the latest stable Egit plugin from here

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;

How do you get files updated from a GIT repository in eclipse?

I have successfully checked out a project from GIT hub but since then changes have been made to the repository. When I right click to team the PULL option is grayed out, when I fetch from upstream it says the files are up to date, but that is not true. I can verify this by visually comparing the file on my computer to the file at GIT hub. Is there any way to resolve this problem other than switching back to subversion?
You need to merge the fetch upstream into your branch to get the updated repository.
Or, you can use terminal
git pull origin master
Check this git pull docs
Also, Pull option is graved out because egit requires the branches to be set up for pull for the option to be available.