0

I followed the steps given as answer to the following question: How to remove a directory from git repository?

However when I execute (last command out of 3)

git push origin master

I get the following error (which I couldn't resolve even when trying to push files/folders without --force):

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/dragGH102/leaderboard-meteor.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I tried with

git pull origin master

but it opens a CLI Interface on which I don't know how to interact (I'm on Linux).

How do I fix this issue?

EDIT _ full shell content:

git rm -r .meteor
> git commit -m "Remove extra directory"

[master e901990] Remove extra directory
 1 file changed, 10 insertions(+), 1 deletion(-)
> git push origin master

Username for 'https://github.com': dragGH102
Password for 'https://dragGH102@github.com': 
To https://github.com/dragGH102/leaderboard-meteor.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/dragGH102/leaderboard-meteor.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.

> git pull origin master

# open GUI (no idea how to interact here and what to do)
Merge branch 'master' of https://github.com/dragGH102/leaderboard-meteor

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
                              [ line 1/8 (12%), col 1/73 (1%), char 0/300 (0%) ]
^G Get Help       ^O WriteOut       ^R Read File      ^Y Prev Page      ^K Cut Text       ^C Cur Pos
^X Exit           ^J Justify        ^W Where Is       ^V Next Page      ^U UnCut Text     ^T To Spell
Community
  • 1
  • 1
dragonmnl
  • 11,330
  • 25
  • 71
  • 115

2 Answers2

2

This will remove directory from git and local

git rm -r the_directory
git commit -m "Remove duplicated directory"
git push origin master

To remove only from git

git rm -r --cached folder_name
Maddy
  • 1,861
  • 1
  • 20
  • 47
1

git pull includes merging and that’s exactly what you are facing. If there was no change in upstream, there would be a fast-forward merge.

Often the current branch head is an ancestor of the named commit. This is the most common case especially when invoked from git pull: you are tracking an upstream repository, you have committed no local changes, and now you want to update to a newer upstream revision. In this case, a new commit is not needed to store the combined history; instead, the HEAD (along with the index) is updated to point at the named commit, without creating an extra merge commit.

However, as both your repo and upstream has changed, you’re facing a true merge.

A merged version reconciling the changes from all branches to be merged is committed, and your HEAD, index, and working tree are updated to it. It is possible to have modifications in the working tree as long as they do not overlap; the update will preserve them.

Since there are no conflicts, you can finish the merge by just typing the commit message.

Source of quotes: https://www.kernel.org/pub/software/scm/git/docs/git-merge.html

More info: https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

Melebius
  • 4,692
  • 3
  • 32
  • 43