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://email@example.com/scm/aim/aim.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:
- 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 xxx.php
- 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
While the changes made by the other developer that came from the remote repository is
- 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.
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.
- Hit OK button to close the Confirm dialog below
- Hit Commit button. Hit Continue Rebase button
- 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.
Unwanted Uncommitted Changes
You may create changes locally accidentally and want to discard them.
- Click to select “Uncommitted changes”. Ctrl-Click the file(s) in Unstaged Files, select Remove.
2. Hit OK button on the Confirm Discard dialog
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.
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
Then select Ignore exact file name in the following dialog.