How do I get MercurialEclipse and Bitbucket to talk to each other? - eclipse

I'm an Eclipse user, but I'm a newbie to Mercurial and to Bitbucket. I think I understand the command-line hg commands. I can create repositories, clone, push, pull, update, that stuff.
If I have a project in Eclipse, I can create a local repository for it. I can't figure out how to clone this repository up to Bitbucket.
If I have a project in Eclipse, I can create a remote repository on Bitbucket. Then I don't have a local repository, so I can't use any of the Team... commands, and can't do anything.
If I have a repository on Bitbucket, I can't get to it, because I don't have a local repository, so again I can't do anything.
If I create separate repositories locally and on Bitbucket, then I have two different repositories, and I don't know enough Mercurial to merge(?) different repositories.
There must be some blindingly obvious to get a project off the ground, but I'm blind to it. I can do this just fine from the command line, but MercurialEclipse is defeating me. No luck so far with Google and assorted documentation...
Help?

Doing it using Eclise "Team" UI:
Create a project in Eclipse and "share" it using Mercurial repository type. That will create local repository (by default in the same location where your project is).
Create project repository on BitBucket.
Use "Team">"Push" to push local changes to your remote BitBucket repo. First time it will ask you to enter the repository URL, user name and password. All this information is available on your Bitbucket web UI.
Don't forget that you have to do 2 stage commits after that. Commit in Eclipse UI will commit it in your local repository. In your team perspective's Synchronize view you will see additional "Outgoing" and "Incoming" entries. Using right-click menu on them you will be able to push/pull your changes to/from your BitBucket repo.
Remote repo information can be managed in special "Mercurial Repositories" view.
More info can be found in the tutorials at http://ekkescorner.wordpress.com/blog-series/git-mercurial/

Following the directions provided by bitbucket should be enough.
You can either create a repository on bitbucket and clone it on your desktop:
hg clone https://bitbucket.org/youraccount/yourproject
...
hg pull -u # to pull changes and update
hg push # to push changes to this repo
Or use a local repository and push these changes to a newly created repository on bitbucket:
cd /path/to/existing/hg/repo/
hg add [...]
hg commit
hg push https://bitbucket.org/youraccount/yourproject
Basically, two repositories are "bound" by:
a common changeset in their history
the [paths] configuration in /path/to/existing/hg/repo/.hg/hgrc, that lists remote repositories you can read/push to.

Related

best way to export Eclipse project to GitHub

I need to export an Eclipse project to GitHub. I am using Eclipse-Mars with the eGit plugin. I have spent hours reading documentation, tutorials, and posts and see that there are basically two ways
Create an Eclipse project and a local Git repository. Commit to local repository. Create a repository on GitHub. Push the Eclipse project to the repository on GitHub. When I try this, I get the error "rejected non-fast-forward". I have no idea why. I did create a .gitignore on GitHub when I created the repository - is that causing a problem?
Create a repository on GitHub. In Eclipse, clone this repository and then add files. Commit to local repository, then push. This works, but I end up with a weird configuration on GitHub:
reponame/myprojname/src
when I would prefer the more normal
reponame/src
Which method is the correct way to proceed? Why do I get the push error in the first method, and why the strange folder layout in the second?
You first need to pull the github code into you local machine.
=> git remote add origin
=> git pull origin master
will automatically fetch and merge the github repo with your local copy. You may need to resolve some conflicts that could be generated due to 3-way merge.
After all this, you can use -
=> git push -u origin master
For the second Point,
If you want src/ directory directly under reponame/ on github, then you should execute git clone after creating the project in eclipse and git clone should be executed inside the myprojectname/ directory.
When you created the .gitignore file on GitHub, you created a commit in the repository that isn't in your local copy. You'll need to add the GitHub repo as a remote, pull the change, and then push your local changes:
git remote add origin <path to your repository>
git pull origin master
git push -u origin master

Synchronizing copied repository with GIT repository

I have copied repository from my team member and I want to synchronize with GIT repository.
Please keep in mind that I am new to GIT and I only have URLs of the repository where I need to synchronize. I need help to connect my repository with GIT repository. I have not imported any repository and I have just copied that. I will be able to push or pull or merge etc. only if my project is synchronized with remote repository. Please let me know that how can I synchronize. Thanks
It's unclear from your question whether you are trying to simply keep two copies of the same repository synchronized or something else.
If it's the first, then what you want to do it a git clone. Your changes should be git commit, to get remote changes you should git pull and to push your changes to your co-worker's repository, you should git push.
Depending on your operating system, there are different front-ends for Git. I gave you the command-line version. I saw you tagged your questions with the eclipse tag, which suggests you are trying to do this inside Eclipse. In that case, you might find EGit useful. See the EGit User Guide here.
If all this sounds too complex for you, you should first Read The Manual - that is, check out the Getting Started chapter of the Git Documentation.
I found the solution. I had to go in team-> share projects. then "create a new repository location" and paste the url of git repository. then team->share project-> git and add the repository. Now my copied repository is linked/connected with my git repository and I am able to synchronize my repository.

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 Local vs. Remote repositories

I'm new to git and am wrapping my head around how I'm supposed to be using git and egit. From the egit tutorial, I have setup a respository on GitHub, pushed my Eclipse projects to the remote GitHub repository from my local workspace, I can push changes to GitHub, switch branches, see the updates on GitHub, etc. This all makes sense.
Looking at the Git Repository explorer, I have a listing of "Local" branches and have no "Remote Tracking" branches and I have no "Remotes" listed. When I create a branch from a local branch, the egit dialog indicates "You are creating a branch based on a local branch" and suggests that I should be making a branch from a remote tracking branch.
So my question is, am I correctly using egit?
Should I just continue pushing changes to the remote GitHub repository? If so, what happens once I share the project and other developers clone the repository and start making changes to the remote repository?
Or should I now ditch the local repository and setup a new remote repository by cloning the existing GitHub repository that I initially created from my workspace?
Or do I create a new Push and Fetch "Remote" for my existing git repository?
Or something else?
Confused.
Since you created the repo on your local system and then pushed it to github without creating a remote you don't have a remote at hand. A remote is simply a short alias for the remote repository's URL. To fix this create a remote and a push and fetch configuration from the repositories view. In order to populate remote tracking branches in your local repo you need to run fetch once. As soon as this is done you can use "Push to upstream" instead of the more complex Team > Push... dialog which allows to define all parameters on the fly. When using native git command line you'll find the same concepts implemented there:
with
"$ git push [url] [refspec]" (e.g. "$ git push https://github/user/myrepo.git master:master")
you pass all parameters explicitly, this is similar to Team > Push... in EGit
with
"$ git push [remote]" (e.g. "$ git push origin")
you push to the repository defined by the configuration parameters of the given remote (check .git/config to see these parameters or open repository configuration from egit preference in Eclipse), this is similar to Team > Push to upstream in EGit. Usually the refspec used in this way is implicitly configured when creating a local branch based on a remote tracking branch. It's also possible to add this configuration later but since this is more
tedious manual configuration the other way is more handy.
If you clone a remote repository the repository you cloned from is stored as remote "origin" in your clone. This way you can skip configuring the remote manually. This is only needed if the repository is born when you create it from scratch.
The "Branching" section of the Egit User Guide can help:
There is no obligation to create a local branch which would be named like a remote tracking branch (see "Having a hard time understanding git-fetch" to have a good understanding of "remote tracing branches).
You can create as many local branches (i.e. branches that you won't necessary push anywhere) as you want/need.
But if you don"t see any remote branch, maybe you didn't fetch that GitHub repo in the first place: see Fetching.