0

I used git rm -r virtualenv to remove my virtual environment from git, not realizing it would delete it locally too. I do still have the this virtenv folder still in my remote Github repository. What commands do I need to run to get it back into my local directory? The project structure was an outer Flask directory for backend files, and inner React directory for frontend, so I have two virtualenv folders to get back.

timman
  • 479
  • 5
  • 14
  • 4
    Checking your virtual environment into version control? That's not a good practice anyway. – iBug Apr 06 '21 at 17:36
  • 3
    Virtual environments are meant to be ephemeral. Rather than checking the environment itself into the repository, just check in your requirements file so that you can easily (re)create the virtual environment as needed. – chepner Apr 06 '21 at 17:41

1 Answers1

1

1- Take everything from git. Git fetch basically downloads everything from the git repo but does not merge anything into your local branch. It just makes sure that you have everything on your computer

git fetch --all

2 - Check out the file or directory you wish. This takes the folder then into your local branch

git checkout origin/<branch_name> <path_to_directory>

3 - Then you can just commit it and push. In your case, it is probably not required but if you were on another branch. You would need these steps. (For example: when you take the original version of a file from master and want to push it to your local branch

git commit -m "..."
git push origin <branch_name>
Berkay Berabi
  • 1,933
  • 1
  • 10
  • 26
  • What does git fetch --all do? How does it know to fetch from remote repo? – timman Apr 06 '21 at 17:40
  • It'd be better if you can elaborate a bit on what it does, than just posting some code without explanation. – iBug Apr 06 '21 at 17:41
  • Sorry, i updated the answer. git fetch does not know anything about the repos. It just takes everything from the git. Then in the checkout you tell your repo with origin/master or whatever and the file//directory you want – Berkay Berabi Apr 06 '21 at 18:59
  • 1
    @timman `git fetch --all` fetches from *all remotes* (`origin` plus any others you have added). If you only have the one standard `origin` remote, `--all` does nothing at all! (It doesn't hurt, but it doesn't help either.) – torek Apr 07 '21 at 02:56