1

I am new to DevOps and Git. (time ago was using VisualSVN)

I wanted to commit a project's new changes to it's DevOps repository which I created earlier. For some days repeatedly I made changes, commit, push to the repository. Don't know why now after some days I am not able to do so. Maybe a time-out thing, a disconnection from the repo.

By the way, after that seems I needed to reconnect to the repo, but after the connection, it repeatedly asks me to clone the same project, which I am working on it.

How can I tell Azure DevOps and Visual Studio that this project is the same project in the repo and sync them.

Guess the question and issue should be a simple one.

Kasrak
  • 1,509
  • 4
  • 24
  • 48
  • 2
    What is your remote pointing to? `git remote -v` – Daniel Mann Feb 17 '20 at 20:44
  • 1
    If you clone a repo locally, you get a `.git` folder in the root folder where you cloned the repo. That folder contains all the information that is necessary for your project in version control and all the information about commits, remote repository address, etc. Removing the folder removes the connection to the repo and any local commits your repo might have. Checking if that folder still exists and where the remote is pointing to like @DanielMann proposes might be a good first step to check what's up. – rickvdbosch Feb 17 '20 at 20:48
  • I have .git folder, as well as .gitignore and .gitattributes files – Kasrak Feb 17 '20 at 21:15
  • Running that command said : "fatal: not a git repository (or any of the parent directories): .git" – Kasrak Feb 17 '20 at 21:21
  • Guess I found the cause of it, but don't know how to solve it, earlier I cloned another project from github, and selected a folder (a different one as the local repository), I think that was the cause. – Kasrak Feb 17 '20 at 21:23

1 Answers1

1

Running that command said : "fatal: not a git repository (or any of the parent directories): .git"

That is the case if you run that command inside the .git folder itself.
You should run git remote -v in the parent folder of .git.
Then you can see if it references the Azure DevOps Git repository.
See "Azure Repos / Clone an existing Git repo" for more.

Actually, after discussion, it appears the .git folder was somehow corrupted.
Deleting it, re-creating it with a git init ., and re-importing it to Visual Studio was a workaround.
But that also means the commit created in it would differ from the existing history of the remote repo.

I would then, after creating a commit in the new local repo, do:

git fetch origin
git reset --hard origin/master
git cherry-pick <the commit created before>

That would apply any modification done locally on top of the remote history.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks, @Vonc, will try that, and post the feedback here soon. – Kasrak Feb 18 '20 at 07:32
  • Oh forgot to mention I ran the command inside the parent folder. – Kasrak Feb 18 '20 at 07:39
  • @Kasrak No you did not, since it said "not a git repository (or any of the parent directories): .git". The .git at the end shows the folder in which you ran that command. – VonC Feb 18 '20 at 07:43
  • I am sure that did this in the parent folder, ran the same command in the new repo which I cloned another project and got the feedback, but for this repo get this error, maybe a corruption, conflict, ... happened don't know, you can't guess any issue here? screenshot may help? – Kasrak Feb 18 '20 at 07:46
  • @Kasrak A screenshot would indeed help. – VonC Feb 18 '20 at 07:47
  • Can not edit those git files to manually map this project with the one in DevOps? – Kasrak Feb 18 '20 at 07:50
  • This is the git settings which I changed earlier yesterday, when I wanted to clone another project from Github. Guess that might caused the issue but exactly not sure why, and how to fix this. I wanted to set that location for some cloned projects from the web, but didn't know later I will be forced to move my current local projects also to that same folder, in another hand not sure also to be able to move the current project's folder and don't want to do so as well. – Kasrak Feb 18 '20 at 08:03
  • @Kasrak What the previous value was for "`Default Repository Location`"? Do you have a `.git` folder in `D:\Repos`? – VonC Feb 18 '20 at 08:05
  • Earlier was C:\Repos, but I always was changing it while cloning every project, running the same command for the last changed local repo will give this result which is pointing to the last cloned project : https://postimg.cc/2V9sKbxL/7189d426 – Kasrak Feb 18 '20 at 08:10
  • @Kasrak That is odd. Each project should be its own repo (with its own `.git` subfolder). `C:\Repos` or `D:\Repos` should not have a `.git` subfolder. – VonC Feb 18 '20 at 08:12
  • That makes sense, and is based on my previous understanding, btw I'm still too new in Git and DevOps, but don't know why I need to re-map my local working project to its related online DevOps repository. – Kasrak Feb 18 '20 at 08:14
  • Sharing HIH .git folder might help? – Kasrak Feb 18 '20 at 08:15
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/208027/discussion-between-vonc-and-kasrak). – VonC Feb 18 '20 at 08:15
  • Awesome, you helped me so much on it! – Kasrak Feb 18 '20 at 09:21