Here's my situation:
I know from having done testing of this locally (git init
, git remote add origin
) that it will see all files in that folder as untracked. If I were to add and commit them, then merging origin/master would cause a conflict with all of them.
Is there a way to seamlessly "insert" an existing repository alongside an existing installation to put it under version control? Note that any upload folders and configs are NOT under version control, so there is no worry about conflicts with these.
I have a submodule in node_modules
, and my approach to attach it to the repo after npm i
is slightly different:
git init .
git remote add origin [url of the repo]
git fetch origin
git branch -f master origin/master
git reset .
(without the push
step, as it gives error: failed to push some refs
error and a git reset .
call in the end)
This is how I would do it:
$ git init .
$ git remote add origin [url of the repo]
$ git fetch origin
$ git push --set-upstream origin master
$ git branch -f master origin/master
(concerning the last command, see also Git: move branch pointer to different commit without checkout and https://www.kernel.org/pub/software/scm/git/docs/git-branch.html which describes the idea).
This works, as git is comparing the SHA1 value of the files in your working directory, which is based on the filename and the content. To prove that it worked, you may run git diff
which will not show any difference (assuming that you really kept the directory in sync with the repo). We can also prove this:
$ git hash-object testfile.txt
77356c31404cfbc88ab78de4025ebd609c022927
$ ls -a .git/objects/77/*
.git/objects/77/356c31404cfbc88ab78de4025ebd609c022927
Note that we now have
However, the staging area still is out of sync. That is why another
$ git add -A
is required (Keep in mind that this operation may become costly if you have many or large files, as all files will be added to the repositories' index). This will synchronize your staging area as well. A git status
then will yield:
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With