Commit and Push keeps making new branch (Eclipse) - eclipse

When using eclipse and I want to Commit / Push changes, using the Git Staging view I can hit commit, then on the Git repositories view push the branch to the remote branch. However when I hit Commit and Push it creates a new branch? The local branch is called master and the remove is origin/HEAD, and the new remote created is origin/master. The default branch is origin/HEAD. I've been Commit and Pushing to the default until today.
I've been searching for an answer for a while but I couldn't really find one, sorry if this is a duplicate.

It didn't [say that the current branch is NO-HEAD]. In the history it says it is HEAD "refs/heads/master" if that's helpful?
HEAD isn't a separate branch. It's just a pointer to the branch that is currently checked out.

Related

Egit: You are in detached head state. This means that you don't have a local branch checked out

I recently created a project on Eclipse. I set up a git repository on the project. Pushed the code to a new repository on GitLab.
I checked out (Import->Project from Git) the project to another laptop, made updates, committed it as another author and pushed it back to repository (2nd commit /revision). I only removed the target runtimes from the project as the changes.
I went to my 1st laptop and wanted to try update / pull my code. I right-clicked on the repository from the Git Repository view -> Remote -> Fetch. I entered the path to the repository and etc and fetched the repository. But, my project still has the old code having the target runtime. I know I only 'fetched' the repository, not 'pulled' maybe.
So I was confused, the code was not updated. If I am not mistaken, I right-clicked the repository again, clicked on 'Check Out'. This was the result :
After 'Checkin Out', the target runtimes on my project were removed, updated like from the 2nd commit. But there are now 2 branches and 2 refs. I don't what state my local repository is in now. And/but the local master branch was still in 'initial commit', isn't it confusing?.. My code has been updated..
I only read a bit of the git manual online, and I haven't yet be able to wrap my head around concepts like refs.
I could just delete the project and Import->Project from Git, right?
But if I can I would like to know what happened to my project (local repository) and how to fix this?
Thx
I'm not familiar with egit and its menus. But I try to answer your question with git commands which you can run in the console. And I think you can figure out which egit menu items are corresponding to these commands.
You wanted to pull and update the local master in the first laptop repository. You needed git checkout master first, which could be skipped if you were already on master and then git pull origin master. However you did git fetch origin master instead, which just updated origin/master with the new commit. It would have been okay to use git fetch origin master if git merge FETCH_HEAD or git merge origin/master followed imediately, because in many cases pull = fetch + merge, but you didn't.
I guess you then did git checkout origin/master. Checking out origin/master leads to detached HEAD state. To make it easier, you could just consider the detached HEAD as a nameless branch. When you make new commits, this namelss branch will grow. But you can't see these commits on other branches unless you apply these commits to them. Git has some commands to apply commits, including git merge, git rebase, git cherrypick, etc.
To fix the current situation, you can simply run git checkout master;git pull origin master.
So to make my answer more simply. Commit changes on your deateached head and make branch with this commit and then merge it together and push to master.
You can just download again your project if you didn't make changes on detached head that you need.

How do "reuse" a branch on Bitbucket / Sourcetree after merge

I was working on a branch of my Bitbucket repo (lets call it "frontend-dev"), which has now been merged with the master branch. I would like to branch again to make further changes, without creating a new branch. How do I branch and get back onto "frontend-dev".
I am using Sourcetree to manage version control.
Normally merging to master does not close or delete the branch. If there are changes in master since the merge from "frontend-dev", you can merge back to "frontend-dev". Either way, you can then simply switch your working copy to "frontend-dev" and continue developing.
Another question discusses what to do when you have closed or deleted the branch: Restore Merged Branch in Bitbucket Repo

Jenkins not building new branch on first push

I am using the github plugin in Jenkins and my automatic builds are working for the most part. However, a build only occurs after the second push to a branch. When I create a new branch using git push origin branch_name:branch_name the jenkins build is not kicked off. I have to make another commit to the same branch for that to work. How can I fix this?
It turned out that my new branch was no different than my old branch so it wasn't viewed as a change. As in it had the same commit history with no additions.
I literally just did
git branch -b new_branch
git push origin new_branch:new_branch
The web hook log showed that jenkins recognized the new branch but said --> no changes.

Eclipse Egit automatically pull changes to local branch

My repository has only one branch HEAD. My local branch is master and I'm usually checked out on my local branch. Now when I pull it won't update my local master. I have to right click on master -> merge, then select remote branches -> HEAD and then updates will be on master too. I went around Internet for hours but I can't seem to understand branch system or how these refs work. Can someone explain what I'm doing wrong and how can I fix it?
And sometimes it pushes a new master branch. (creates a new branch itself)
My repository has only one branch HEAD
But HEAD isn't a branch. It represents what will be committed, but it can be a detached HEAD.
See more at "EGIT branches local vs Remote tracking", where you can see an history with no HEAD
The other explanation is when your master branch has no upstream branch associated to it.
You need to:
configure the upstream push
specify the refspec associated to your local tracking branch
That will fetch any branch from the remote repo and put then in the refs/remote/origin namespace.

How to switch branches in eclipse without commiting changes

I've been using GIT for a couple of weeks now and trying to understand how to switch branches without commiting files. This is what I have done.
Cloned a git repository and have a local master branch.
Created a new local branch (Branch2) which is based on a remote branch.
Made changes to 2 files in the master branch.
What I want to do now is switch from master to Branch2.
The changes I made to the master branch are for local dev purposes only and should never be committed.
But when I try to do this in eclipse (i.e I double click on the local branch I try to switch to) it keeps telling me that there are uncommitted changes and I need to commit, stash or reset.
Can anyone tell me how i can make a change to a local file and have git ignore this change so that I don't get prompted with this message?
Note: if you need to stash a work in progress from Eclipse, Egit now supports stash:
Have a look at git stash. Stash allows you to store uncommitted changes.
Option 1
git stash
git checkout -b Branch2
Your changes will be stored in git (locally). When you want to re-apply those changes, you will do git stash pop and it will apply those changes for you.
Option 2
git stash
git stash branch temporarybranch
This will take your uncommitted changes to a new branch and keep them there for you. Compared to the previous option, this allows you to keep these branches on the server by pushing this new branch.
Hope it helps
If you don't want the changes to be ever made public you should just commit them in your own feature branch and not on the master branch.
You can create a new branch, give it a name that reflects the changes, maybe prefix is with something like "experimental-" and then commit to that branch before switching to your other branch.
You can use git stash to stash your changes, or use git stash to commit them directly to a new branch as mentioned by Ege Akpinar.