How to push changes to Git repository from uninitialized directory
-
21-12-2019 - |
Question
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:
git clone … ./
- repository clonedrm -Rf ./.git
- repository no longer initializedvi ./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.
Solution
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.