Push to main instead of master from eclipse to git - eclipse

I have been searching and I found git commands to change the repository but I'm new on github and I don't know how to make that from eclipse, everytime I push I make the changes on the master branch instead of the default main, when I try to push the main it says non fast forward and I can't do it, thanks.

Select Team > Advanced > Rename Branch
Rename local as main
Rename remote to main

when you first commit your project in eclipse and then you click on push
after filling the information of the repository you get this
you will write main here insted of master and your project will be pushed directly to the default main
my solution is only when you first upload your project to GitHub

Related

How do I get a new branch to show up in Eclipse Git Remote Tracking?

I have an existing Eclipse git project, with a master and development branch present in both local, and remote tracking. I have just added a new branch in my git repository, but I can't figure out how to get it to show up in Eclipse.
I have tried to read up on the subject, but it seems like it is just expected to automatically show up. I have found a lot of similar questions, but they all seem to deal with the issues of a completely empty remote tracking folder, instead of my problem of only a single new branch missing. I already have Master and Develop present.
Here is what does not work:
Clicking refresh in the Git repositories window.
Any kind of synchronize, pull or other update I can find
Here is what would work:
Right clicking the remote tracking folder, and selecting "Paste repository path or URI". If I do that, and select the exact same path as is already there, I can see my new branch. This action does require that I completely clone the whole repository to an empty folder again, and that can't be how this is intended to work.
I believe it might work to use some kind of command line tool, but I really want an Eclipse solution to this, as I feel sure it exists, and I am just missing something.
In the Git Repositories view:
Right-click the repository and choose Fetch from Upstream
If the new branch will not shown up below Branches/Remote Tracking, you have to configure fetch:
Right-click the fetch node below Remotes/origin and choose Configure Fetch...
In the Configure Fetch make sure there is only the single Ref mapping (assuming the remote is named origin) +refs/heads/*:refs/remotes/origin/*:
In case you do not see Fetch from Upstream after right-click the repository, you may look for Fetch from origin.
For me the solution was almost what Joshua suggested, however it did not work as described. For me the solution was to configure the [remote "origin"] property as follows:
[remote "origin"]
url = your_git_url.git
fetch = refs/heads/*:refs/remotes/origin/*
Alternatively, you can do it from the Eclipse UI too:
Fetch from origin... then hit Configure... and in the configuration window hit Advanced... and there you have the option to Add predefined specification where you can selec Add All Branches Spec. This will result in the same configuration as above:
Maybe you have to remove your original entry which will be pointed out as a duplicate by Eclipse.
You need to modify the "config" file in your local git repository folder. For example, you cloned a remote branch Project into c:\git\MyProject local folder. In this folder there is a hidden folder ".git" that has a "config" file. There is a section in this file resembling the below
[remote "origin"]
url http://xxxxxxxxxxxxxxxx
fetch = +refs/heads/Project:refs/remotes/origin/Project
You need to modify this section as below
[remote "origin"]
url http://xxxxxxxxxxxxxxxx
fetch = +refs/heads/:refs/remotes/origin/
Then go back to Eclipse IDE, right click on the repository and do a "fetch from origin". Now all the branches will show up.
What I did:
1: disconnected.
2. refresh and pull. Then, it shows the new branch
3. create local and pull.

Eclipse, Egit, Github: remove pushed project folder

I have successfully created a git hub repository, a local master, committed the initial changes and pushed them to github.
Unfortunately the project folder from Eclipse ends up in the repository. For example:
<username>/<gitrepositoryname>/<eclipse project folder>/<project files & README>
when for most people it looks like:
<username>/<gitrepositoryname>/<project files & README>
I created a new local master after I found this tutorial Push eclipse project to GitHub with EGit
but now I am running into push problems such as "HEAD rejected - non-fast-forward" when using the new local master.
Can some please help me to correct this locally/remotely? Is there a way to switch local master branches so that I can sync the correct one with githib?
Thanks in advance.
It's pretty simple to fix:
Go to the "workspace" where you keep <eclipse project folder>
Make sure to delete the .git folder there
Tell git to force push the changes. (Checkbox) (It's usually not good to force git to do something, because you could loose commits/data BUT here, we really want to overwrite the old repository with the new one.)
Your changes should be up immediately. Next time you push, please make sure, the force push checkbox is disabled again

Pulling a project from GitHub with EGit

I've setup a private GitHub account to make it easier for me to work on the same project on both my desktop and my laptop when I'm not at home. The project was originally on my laptop, so I configured EGit to push and commit to my private repo. That worked successfully, and now I can see my project when I log onto GitHub. I'm now trying to pull that project onto my desktop. I did the same configurations , and in the Git Repository View within Eclipse I can see Remotes->origin-> the Push/Fetch streams. I tried to fetch, and that placed an origin/master branch under git\branches\Remote Tracking. But I can't seem to do anything with it.
I'm not sure what to do next, or if I made a mistake somewhere?
Now just right click it and Create branch.... This will make a local branch that will track this remote branch. When you push Eclipse should automatically configure everything so that origin/master will get updated.
Check out the local branch to start working.
UPDATE:
To import the project from working copy select the following:
If you have checked in your configuration files (.project, .classpath etc) you will get a list of all available projects in the repo to import to workspace. If not you will need to import them manually.

EGIT rejected non-fast forward

I'm on Eclipse 4.2.1 (Java) and trying to use EGIT. My account is all set up on Github. No one else is working on it so there are no changes. I have a very simply project containing a single file with one print statement.
I created my local repo and added the project. (project explorer shows: [gitrepo1 master])
In project explorer:
right click on project -> team -> remote -> push
But I get: master: HEAD [rejected - non-fast-forward]
I've configured the push:
Branch -> master
URI -> ssh.git#github....
Ref mappings -> HEAD:/refs/heads/master
What am I doing wrong?
We had this problem, because we amended a commit after pushing it.
The solution was to merge origin/master (in Branches > Remote tracking), then push.
egit works by using jgit which is an implementation of git that is using java. the best thing to do is verify that the repo works with the normal git client. From your question it is not possible to know exactly how things ore configured.
When you get the error message that you could not do a push because it is not a fast forward, it means you need to do a pull first then, do the push, so try that.
Same cause as Bernát: I amended a commit after pushing it. Merge failed because of conflicts.
My way out: Context menu 'Team/Reset' selection 'Remote Tracking'/'origin master' option 'Mixed'. After that all my changes since last push were marked and I could commit and push.

Eclipse/Egit, Push to Remote menu choice is grayed out

I created a repository on GitHub. I set up a local git repository using Eclipse and Egit.
With Team > Remote > Push. I managed to push the local repo to the one on GitHub.
Now I expected to be able to use the Team > Push to Upstream (as well as fetch from upstream) as a one-click push (and pull/fetch), but this menu choice is not available (grayed out). I have to use Team > Remote > Push to each time manually fill in the info (ctrl+space helps).
Following this, I created a remote configuration and pushed from the repositories view, and I can see the remote GitHub repository listed under Remotes but still the Team > Push to Upstream command is grayed out in the menu.
Could someone please give me a hint as to what I have may done wrong?
Here's what I did and this worked fine:
Right click your project, choose Team→Show in Repositories View. You will switch perspectives and be in the Git Repositories tab.
Right-click "Remotes" and choose "Create Remote". For "Remote name", enter "origin". Click OK.
Click Change. Enter your information as you did during your initial push. Click Save.
You should now be able to push by merely right-clicking on your project, then Team→Push to Upstream.
Because the remote was added under the project in question, each project can have its own upstream origin and they will not interfere (whereas the Window > Preferences solution is a global setting).
Based on your description of what you did, it appears you attempted this - but possibly did not use the name "origin" for the remote, which is absolutely necessary. I stumbled across this solution by pure chance.
I had this problem and thankfully found a way to re-enable the "Push to Upstream" option.
Go to Window > Preferences > Team > Git > Configuration.
Select the Repository Settings tab and then the repository that represents your project.
Click "New Entry..."
The key is remote.origin.url
The value is the url you copy from github. It's usually offered predominantly on whichever site you register with.
Perhaps there is a neater way of achieving the same thing. Once I reached this far I stopped looking because it works now.
You need to have the following type of configuration in that repository's .git/config file:
[branch "master"]
remote = origin
The remote setting can be any of your remotes or just a value of .
You can edit the repository's config by selecting the Properties menu item from the context menu for the repository in the Git Repositories view.
I came here searching for solution to solve similar problem with bitbucket - although none of the two highest votes answer didn't work for me, it proved that I had option "Put branch...", when I tried to do this, it says "Non fast-forward", but when I successfully made "pull", I was able to push to upstream.
Maybe it will help someone :)
This post might be a little old, but I had the same issue with one of my repos the following information from this link worked for me: Adding a remote to an existing git repo
The part i want to highlight from that article is the following:
[branch "master"]
remote = origin
merge = refs/heads/master
When I made the change in the .git/config and refreshed eclipse the "push to upstream" link worked for me. Keep in mind, I am assuming that you have a remote configured in your Git perspective for your remote repository.
In my case all git commit/push operations are inactive. I fixed the issue by placing the repository folder under git directory.