Thursday, September 11, 2014

Using git hub with eclipse (EGit)

UPDATE: the first section talks about dealing with existing local repo
I added a new section to clone a repo from the scratch by EGit without using any external tool like Git Bash


Section 1 : Working with existing Repo

Today I'm going to try EGit to integrate a local and remote repository with eclipse

let's start by running eclipse > File > Import :

1
2
3




4

5


6

Then I added a Class called Tester to this project and committed it through git bash ( to test if eclipse will sync if I use git bash)

7


8

9

 Until then the project didn't look like it was connected with my local repository, I right-clicked the project in eclipse > Team > share project :

10


11

After I clicked finish the source control icons in eclipse appeared :

12

so eclipse connected well to the local repository without loosing any info as you can see 'Tester.java' is appearing as committed.

Now we will start using EGit, and to do that I added another class 'Tester2' and committed it:

13
14

Now the file is committed, let's try to push it to the remote repository:
right click the project > Team > push branch 

15


16


17

Done! very smooth process with good GUI from eclipse to do basic functionality like adding files and committing then push to remote, lets try more features.

1- branching

create new branch 'dev-adding-feature1':
1
2

add new Interface : Feature1.java, at first the file won't be tracked by git, to add it to the tracking tree right click the file > Team > Add to Index :




3
This file will now appear like this in the commit screen:

4

 but we also want to remove the configuration files from appearing here since they are not to be committed, let's add them to the ignore list:
switch to navigator view (  window -> open view -> navigator )
5
Now the commit screen is clean :

6

Now let's commit and push to the remote repo:

7

8


9



10


this will create a new remote branch on git-hub
11

let's do a pull request and merge dev with dev-adding-feature1

12

Now dev has feature1 folder and interface:

13

Now let's switch locally to the dev branch instead of dev-adding-feature1 to update our local dev branch with the new changes:

before update (no feature 1)

go to Team > Remote > Fetch From ..

14








15

16

17


Now the HEAD changes are fetched for all repositories, we will need to merge the remote dev branch with our local dev branch to see the changes: 

go to Team > Merge..

from local section, dev branch will be selected, and from Remote section, select origin/dev
Now the new commits (changes) will be available in our local dev branch.

another way to do this is to do a Pull. it will automatically do a fetch then merge.


if a conflict happens we will need to resolve it before merge is possible.


Section 2 : only using EGit to clone the repo:

to clone a repo go to File > Import , Select Git




Select Clone URI, then copy the https url and put in your git hub user name and password:




after that the info of the repository will be fetched


Click next and choose the branch that you want to work in, for now I selected master.
after that you will be promted to select a project, in my master I didn't had any so I had to finish the wizard there.



Now because I didn't select the proper branch [ has no projects ] to switch branches in EGit go to to:

Window > Show view > Others : Git > Git Repositories



right click the repo name and you can switch branches :


then create a new local branch and check it out then import the project as in section 1.





No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Istio —simple fast way to start

istio archeticture (source istio.io) I would like to share with you a sample repo to start and help you continue your jou...