Technical Team – Getting Started – Common Issues with Git (Mac OS X)

Previous || RM Table of Content ||

Push and Merge errors

Push errors may occur when a developer pushes changes after another developer has already pushed other changes to the remote repository. Since the local history has diverged from the remote repository, Git generates an error like below:

error: failed to push some refs to 'https://xxxxxx@stash.uconn.edu/scm/famis/famis.git'

hint: Updates were rejected because the tip of your current branch is behind

hint: its remote counterpart. Integrate the remote changes (e.g.

hint: 'git pull ...') before pushing again.

hint: See the 'Note about fast-forwards' in 'git push --help' for details.

In this case the developer needs to pull the updates from the remote repository by:

  1. Click the Pull button in SourceTree (make sure the check box “Rebase…” is checked) and click the OK button as shown below. The –rebase option tells Git to move the commit(s) to the tip of the test branch.

    Merge conflict occurs:

    CONFLICT (content): Merge conflict in direct/fac_wo_ticket_u1.1.php
  2. Open the file in any editor (See the example below) Git automatically adds markers to mark changes from different sources:
    <<<<<<< HEAD
    
    print_r($_POST);
    
    =======
    
    print_r($_GET);
    
    >>>>>>> Just a test

    Text from <<<<<<< HEAD to ======= comes from the remote repository. And the rest comes from the local changes. Note that “Just a test” is the commit message entered by the developer. More specifically, the developer codes the line

    print_r($_GET);

    While the changes made by the other developer that came from the remote repository is

    print_r($_POST);

    gitconflict

  3. Edit the file as necessary after a discussion with the other developer (for example keep the change print_r($_GET);), save the file. Ctrl-Click the file in the unstaged files area in SourceTree, select Resolve Conflicts->Mark Resolved.
    sourcetreeconflictresolvingmac
    Note: Two quick shortcuts for steps b and c are to use Resolve Using Mine, and Resolve Using Theirs to use the change from self or from the other developer.
  4. Hit OK button to close the Confirm dialog below
    sourcetreeconfirmresolvedmac
  5. Hit Commit button. Hit Continue Rebase button
    sourcetreeconfirmrebasemac
  6. The conflict was resolved in the local repository. Test branch should be ahead and there is a push notification. Click the Push button in SourceTree to push the changes to the test branch of the remote repository. On the Push dialog, click the Push button.

sourcetreepushdialogmac

Unwanted Uncommitted Changes

You may create changes locally accidentally and want to discard them.

  1. Click to select “Uncommitted changes”. Ctrl-Click the file(s) in Unstaged Files, select Remove.

sourcetreeunwantedchangesdiscard

2. Hit OK button on the Confirm Discard dialog

sourcetreeunwantedchangesdiscardconfirmmac

Unwanted Commits

You may want to reset your local branch to remove unwanted commit. In SourceTree, make sure test branch is checked out, select the commit you want to be on the top, Ctrl-click and select “Reset test to this commit”. You may have to close/re-open SourceTree to see the refreshed commit graph.

sourcetreeresetunwantedcommitmac

Non-Versioned Files

Files that are created by the IDE are not needed in Git. If seeing the files in SourceTree, simply right click (or Ctrl-Click in Mac OS X), and select Ignore

screen-shot-2016-12-09-at-9-33-15-am

Then select Ignore exact file name in the following dialog.

screen-shot-2016-12-09-at-9-33-20-am