DEV Community

Bing Pan
Bing Pan

Posted on

Eclipse, WSL 2, & Git

I. Working on parallel branches, merging them, pushing to Github

  1. On my local machine, create a folder to contain for the entire project.

  2. In the newly created folder, on the command line, issue:
    git init
    then, pull the remote master repository from Github.com by:
    git clone https://github.com/bpan2/httplinkchecker

  3. Once cloning is done, at the current folder, create two new branches to implement two features for json and all/good/bad flags by issuing:
    git checkout -b issue-json master
    git checkout -b issue-flags master

  4. Import the master branch into Eclipse with the option of "Select nested projects".

  5. Implement the above two features in their corresponding local branch.

During the entire implementation process, I staged and committed changes via Linux command line.

For each commit, I tried to make the content as atomic as possible. By this way, it could make reversing the modification easier.

  1. Once the implementation is completed, I ran into some issues when trying to push my local branches to the remote repository.
    I named my remote branch with different names from my local branches. Even though I tried

      git push origin issue-json:issue-4
    

    I kept getting the error message which states:

      Updates were rejected because a pushed branch tip is  
      behind its remote counterpart
    

After multiple times of failed attempts to solve the issues, I resorted to the most primitive method:
1. deleted the corresponding remote branches for the two
features

 2. within each local branch for the two features, change the  
 name of the branch by issuing:
      git branch -m issue-4
      git branch -m issue-5

 3. at the command line, issue:
      git push -u origin issue-4
      git push -u origin issue-5 

The resulting remote branches can be found via:
https://github.com/bpan2/httplinkchecker/tree/issue-4
https://github.com/bpan2/httplinkchecker/tree/issue-5

  1. Merging issue-4 and issue-5 branches with the master branch

    The merging of issue-4 branch with the master branch goes without any issue. However, multiple conflicts occurred when merging issue-5 branch with the master branch.

    The conflicts involved tow java classes. By examining the conflicts, no real conflicts exist in terms of the implementation codes. Once finishing removing the signs generated by git, the issue-5 branch is merged with the master branch without any issue after the changes were committed.

    After completing the above two merges, I retrieved those two merge commits by issuing:
    git log --merges

  2. Filing issue-4 and issue-5 and closing them with the following two links:
    https://github.com/bpan2/httplinkchecker/issues/1
    https://github.com/badalsarkar/Blink/issues/5

II. Useful Details

  1. Using Windows Subsystem for Linux version 2(WSL) on Windows 10:
    To use WSL, issue "bash" at the Powershell command line.

  2. How to import local repo into Eclipse:
    While importing a local Git repository with multiple branches, don't forget to tick the checkbox for "Select nested projects". Otherwise, you might not be able to switch among branches within Eclipse.

  3. How to switch branches using Eclipse by using Team:
    Right click on my project,
    select Team -> Branch -> switch between existing branches

  4. Creating a new remote branch and push a local branch to it:
    git push -u origin issue-4

  5. Filtering the git log to display/not to display merge commits:
    1 to display: git log --merges
    2 not to display: git log --no-merges

Top comments (0)