Hear me out, not a duplicate.
Hi, I have a repo on gitlab which I downloaded on my local machine in zip format. Now, I want to link the downloaded local project to that existing project on gitlab. For that I did git init
and then git remote add origin <SSH url of the repo>
. It did made it a git repo and the origin has been set properly, but, all of my files have turned red(in PhpStorm), indicating that these are the new files, however the same version is present in the repo.
When I try to run git checkout master
or git pull origin master
it aborts the process: error: The following untracked working tree files would be overwritten by checkout:
.
On all the related answers that I've seen so far they have said to use git add .
and then do the initial commit and push into the repo, but, the thing is I don't want to commit or push anything right now to the repo as I think it will change all the files.
How can I make it work so that I can switch to master branch or take pull from master branch? Am I missing something basic here? Please help. Thanks!
The reasons why I'm not just taking a clone and deleting this is that, this project is dockerized and I've run all the docker commands in this folder already.
CodePudding user response:
I tested with the following steps:
# (download zip from github.com/mattneub/testing)
# (open zip)
% cd [the newly created folder]
% git init
% git remote add origin [email protected]:mattneub/testing.git
% git add .
% git switch main
Branch 'main' set up to track remote branch 'main' from 'origin'.
Already on 'main'
That's it. Nothing new happened to the files I could see, but later if I wanted to I was also able to create, edit, and add a file, and then commit and push — thus proving that we are totally coherently synced to the remote.
CodePudding user response:
The error you are getting is related to git struggling to recombine the repo. You should put your local files on a different branch, pull down the master branch, and then merge the branches together.
First, make a new folder and clone the remote repository directly. git clone remote_url
. Doing this fresh will make sure you have the correct commit history and all the correct data. Now, inside your freshly cloned repo, run git checkout -b local
. This creates a new branch called local. Now, move all the files from your unzipped project into the repo, overwriting files as nessecary. Now, your local branch will contain the contents of your zip file, but will also be able to show you exactly where the differences are to the remote repo. A command like git add -p .
will take you through place-by-place where git thinks your zip files and remote repo differ. If they are truly identical, then there will be no difference.
Once you've git add
ed any changes (note, there might not be any changes), you can resync the branches. Just merge the local branch into master. After that, you will be on master in a correctly configured repository with all your zip data right there.