2

I have a local copy of all files from some Git repository in a uninitialized directory, i.e. not tracked by Git (without .git in it) and I've introduced some changes to it. How do I push those changes to the remote Git repository?

These actions can describe what I mean:

  1. git clone … ./ - repository cloned
  2. rm -Rf ./.git - repository no longer initialized
  3. vi ./somefile - some changes introduced

In a more practical aspect:

I have a cloned directory of some library created by bower dependency management tool. I've introduced some changes to this library and now I want to push those changes to the master.

I'm looking for a smart way to re-initialize this directory with Git and to push changes as a single commit to the remote repository.

Slava Fomin II
  • 26,865
  • 29
  • 124
  • 202
  • 1
    You can't. You *must* keep the .git directory in order to interact with other copies of the repository. – Code-Apprentice Jun 04 '14 at 03:30
  • @Code-Guru Thanks for your response! I know it is possible to achieve this by re-initializing directory with Git. I'm just looking for smarter method of doing this. I will update my question to reflect this. – Slava Fomin II Jun 04 '14 at 03:35
  • The smarter way would be to use git as it's intended. – Code-Apprentice Jun 04 '14 at 03:37
  • @Code-Guru Git is used to acquire project dependencies by many package managers like `Composer` and `Bower`. It's accepted industry practice. I'm looking for a way to quickly introduce changes to this packages. – Slava Fomin II Jun 04 '14 at 03:40

1 Answers1

3

I'm looking for a smart way to re-initialize this directory with Git and to push changes as a single commit to the remote repository.

Easy: initialize it somewhere else:

cd /path/to/somewhere/else
git clone /url/to/bower
cd bower

Then reference your old folder (where you did some changes) as the git working tree while you are in the new cloned repo:

git --work-tree=/path/to/old/folder add .
git commit -m "changes'
git push

See the --work-tree option of the git command.


In theory, you could do the git clone directly in your old folder with git clone -n:

cd /path/to/your/old/folder
git clone -n /url/of/bower .

(It might complain the folder isn't an empty one, in which case do the git clone -n outside, and move the .git folder in your old folder)

But I prefer keeping the old folder intact, and doing git-related operations in a separate clone.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250