Reputation: 1699
I have a local directory that contains the source code, minus the .git
folder, so it has no git integration. I want to add the remote and pull down any changes. I tried git init && git remote add origin https://...
, however it wants me to make an initial commit. As there is an existing project, I don't want to make an initial commit.
How can I add the remote repo remote and pull down changes without an initial commit?
Upvotes: 1
Views: 274
Reputation: 124646
I want to add the remote and pull down any changes.
You can turn the local directory into a Git repository, add the remote, and fetch its content.
git init
git remote add origin repo-url
git fetch origin master
When you say "pull down any changes", it seems to suggest that you don't have local changes, you just want to be up to date with the remote repo. If that's the case, you can hard-reset the local repo to the remote, discarding any local differences:
git reset --hard origin/master
As a result, the local directory will be up to date with the remote repo,
and it will be a proper Git repo with a .git
directory.
Upvotes: -1
Reputation: 41
You are on the right path. However, to answer your question, you cannot, at least not without cloning/forking. If you just adding your code to an already existing repo, and you are a collaborator of said repo, you can branch the repo, add your code, and pull request for the owner to merge your branch into the master.
If you are the only dev on the project your init commit and subsequent push simply add the project to server, and thus start the git magic of version control.
Upvotes: 0
Reputation: 1324258
Easier would be:
git clone /url/remote/repo
git --work-tree=/path/to/source add .
git commit -m "update repo with local source"
git push
The trick is using the git --work-tree=<path>
option in order to add files which are not in the current local repo worktree.
Upvotes: 2