Question: I have a git project in a folder and I want to add this folder in my git projet, but without adding other folders at the same parent folder. So I can not just init new git in parent folder and push, because folder\_1 will be added too. 

folder\_2 contains a plugin for an application and it have to be named "folder\_2". So when someone download from git, I want he has a "folder\_2" folder with plugin files inside. 

Now the folder\_2 *content* is in git : 

```
parent_folder
|_ folder_1
|_ folder_2
   |_ .git
   |_ machin.html => in git
   |_ truc.html => in git
   |_ bidule.html => in git

```

What I want, is the folder\_2 itself in git, but without the folder\_1 : 

```
parent_folder
|_ .git
|_ folder_1 => NOT in git
|_ folder_2 => in git
   |_ machin.html => in git
   |_ truc.html => in git
   |_ bidule.html => in git

```

I try init new git in parent\_folder and add folder\_2 only in new branche. But i can not merge now : 

```
$ git push -u origin master
To https://gitlab.......git

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://gitlab........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.

```

Note : --force doesn't work.

Answer: 
*UPDATE* - It was not clear from the original question, that OP wanted to *move the path* in an existing repo, not create a new repo as was previously implied

---

Well, in fact you *could* just `git init` in the parent folder - because only the files you stage (via `git add`) and commit would be pushed - if you were creating a new repo. Since you're modifying an existing repo, while you could still make that work a different approach is simpler:

First, clear the index

```
cd .../parent/folder2
git rm --cached -r .

```

Then move the `.git` folder

```
cd ..
mv folder2/.git .

```

Repopulate the index and commit

```
git add folder2
git commit

```

You might then want to use ignore rules to prevent `folder1` from being accidentally added.

(You could put the ignore rule in `.gitignore` at the root of the work tree, if the exclusion will "make sense" in the broader context of the repo; or if `folder1`'s presence is really just a thing on that particular machine, you could put the exclusion in `git/info/exclude`)

However, unless there is other content at the level of `parent` (or other subdirectories of `parent`) that should be included in the repo, this seems like a lot of headache just to have the repo's top-level folder contain a single entry named `folder2`; I can't really think of any reason not to just create the repo from/in `folder2` based on the information provided in the question.
1. Go to `parent_folder/folder_2`
2. Create `folder_2` dir in `parent_folder/folder_2`
3. Move all content from `parent_folder/folder_2` to `parent_folder/folder_2/folder_2`
4. Copy `parent_folder/folder_1` to `parent_folder/folder_2`
5. Do `git add --all . && git commit -m "Import folder_1"`
6. Do `git push`
7. Move all content (don't forget `.git/`) from `parent_folder/folder_2` to `parent_folder`. Verify result with `git push`