Skip to main content
  1. Learn
  2. Software Development
  3. Guides
  4. Git tutorial
  5. How to use Git
  6. How to use Git on Command Line
  7. Make a conflict
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

Make a conflict

When a conflict arises, you will need to resolve it to complete your work. In this step, we will deliberately create a conflict using our two existing repositories, “tutorial” and “tutorial2”.

First, open the sample.txt file in the tutorial directory. Add the bold text below to the file and commit the change but do not push just yet.

Anyone can learn Git with this tutorial and Backlog


add: Register a change in an index commit: Save the status of an index

$ git add sample.txt
$ git commit -m "append description of the commit command"
  [main 95f15c9] append description of the commit command
    1 files changed, 1 insertions(+), 0 deletions(-)

Next, open the sample.txt file in the tutorial2 directory. Add the bold text below to the file and commit.

Anyone can learn Git with this tutorial and Backlog


add: Register a change in an index pull: Obtain the content of the remote repository

$ git add sample.txt
$ git commit -m "append description of the pull command"
  [main 4c01823] append description of the pull command
    1 files changed, 1 insertions(+), 0 deletions(-)

Now use the git push command to push the change from “tutorial2” to the remote repository.

$ git push
  Username: <username>
  Password: <password>
  Counting objects: 5, done.
  Delta compression using up to 4 threads.
  Compressing objects: 100% (2/2), done.
  Writing objects: 100% (3/3), 391 bytes, done.
  Total 3 (delta 0), reused 0 (delta 0)
  To https://example.backlog.com/git/BLGGIT/tutorial.git
      3da09c1..4c01823  main -> main

In our current remote repository, the sample.txt file contains the third line pull: Obtain the content of the remote repository and has been committed in the history log.

Next, we will push the commit from our tutorial repository to the remote repository.

$ git push
  Username: <username>
  Password: <password>
  To https://example.backlog.com/git/BLGGIT/tutorial.git
  ! [rejected]        main -> main (non-fast-forward)
  error: failed to push some refs to 'https://example.backlog.com/git/BLGGIT/tutorial.git'
  To prevent you from losing history, non-fast-forward updates were rejected
  Merge the remote changes (e.g. 'git pull') before pushing again.  See the
  'Note about fast-forwards' section of 'git push --help' for details.

As you can see, Git raises a conflict and rejects your push.

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life