Within Eclipse, switch from using the Master branch in the Local Repository to something else - eclipse

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.

Related

Merge GitHub branch into local branch

I have the following situation: I have an application checked out from GitHub, made some changes and checked it in a local repository (Bitbucket). During months I added new functionality into this local repo.
In the meantime, the GitHub project has been further developed.
Now I'm looking for a way to merge the GitHub master branch into my local master branch. It would be nice if I can do it in eclipse. How should I proceed and how can I avoid conflicts?
In the Git Repositories view:
Add an additional remote/upstream repository: right-click the node Remotes and choose Remote Remote...
Fetch from the GitHub repository: see EGit User Guide - Fetching from other Repositories
Merge changes from a remote branch of the GitHub repository into a local branch
Consider also to contribute back your changes to the GitHub project.

Eclipse pull project to develop on another machine

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.

How to convert a remote branch into a local one in Eclipse using Bitbucket?

I'm kind a newbie on Bitbucket so I have a lot of doubts.
I share an Eclipse project between two different computers. I have pushed the project from one computer to the Bitbucket repository using the Eclipse plug-in. Now when I go to the other computer I have fetched the repository that is saved on Bitbucket, and it has created a new remote tracking branch on my Eclipse local repository.
My problem comes when I want to merge that branch with the local branch, I have no idea how can I do that
Anyone could help me?
ps: sorry if the problem or the situation is not very clear
You should follow the section "Pulling New Changes from Upstream Branch ":
a git pull is a fetch + a merge.
Right-click on a project in the Package Explorer and select Team > Pull or right-click on a repository in the Git Repositories view and select Pull to pull new changes from the upstream branch your local branch is tracking.
The section "Fetch and Pull" of the Egit tutorial says as much:
When cloning remote repositories, Git creates copies of the branches as local branches and as remote branches.
A Fetch operation will update the remote branches only.
To update your local branches as well, you will have to perform a Merge operation after fetching.

Egit push doesn't change files in remote repository

I came to know about the git / egit version control system last week, seems too good to be true .So thought to shift from SVN to git..Since last week I am trying to understand the basics and concepts of git.
So I created a test environment for understanding the workflow of egit in eclipse as following.
I am following the strategy of remote tracking there are two repositories named local and remote used for understanding the workflow.
I created a repository named 'remote' with an emtpy index.php file and has one master branch and imported the project into eclipse.
I created another git repository named 'local' by cloning the above 'remote' git repo, this repository is now tracked by 'remote' repository has one master branch and origin/master remote tracking branch.
I imported the project from 'local' git repo. into my eclipse workbench and changed the index.php file using eclipse php editor -> committed changes to local's master branch and -> performed push from local master branch.
When checking the remote working directory .. there is no change updated which I did in local's index.php file , however master branch in the remote repository view shows the latest commit which I committed in the local's master branch, but unfortunately files are not updated, it just adds asterisk mark to all changed files in my remote project view.
So researching about the asterisk mark I found its in staged condition .So can anyone lead me to the right way explaining how to successfully perform push operation from local's master branch to remote's branch I will be grateful.
this is the picture of my egit test case set up in eclipse for understanding the workflow. you can see the asterisk mark in the remote project after performing push from local repository,you can see all three branches viz.local's master, origin/master and remote's master branches shows same latest commit.
1
Thank You.
I tried using bare repo. as a remote, when I push from changes from local to remote, I don't find any files in remote repo. Just branch gets updated with the latest commit.
That seems normal, since a bare repo has *no working tree, meaning no files.
You would need to clone that remote repo, and add this cloned repo (non-bare) as a project in your Eclipse, in order to:
push from your first Egit-managed repo to the bare remote repo
pull from that same bare repo to your second Egit-managed non-bare repo.

Egit can't fetch README changes

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.