0

My local branches got wiped and I would like to retrieve the files I've been working on from Github. I am new to Git and am not sure how to do this. From Googling, this is what I've tried:

  • Created new branch with same name: git checkout -b some-branch
  • Used git pull to pull in my files, eg git pull project-name some-branch

However, this seems to pull in a lot of other files, not associated with what I am working on.

Would anyone know how to set up my branch again and retrieve just my files?

3
  • Did your local branches had remotes? Without remotes, you cannot recover lost local branches... Commented Jun 25, 2018 at 2:13
  • Have you ever push your change to your remote (Github)? if so, you should have already see your remote branches when git branch all. If so, just checkout the corresponding branch and you are all good Commented Jun 25, 2018 at 2:30
  • Yes I have pushed to Github and have a pull request (I did this before the branch was deleted from my local). When I try to git checkout my-branch-name I just get the error fatal: Not a git repository Commented Jun 25, 2018 at 3:17

2 Answers 2

2
  1. From your comments, it seems like you are not running git commands from the git repository. This can mean that either you are running the commands in the wrong place, or you deleted the .git folder. If you have deleted the .git folder, clone your repository from github, as you have mentioned in the question.

  2. To get the branch code, the best way would be to move inside your respective git repository and run git fetch origin some-branch then git checkout some-branch

Sign up to request clarification or add additional context in comments.

Comments

1

Do you see your work on Github.com? If so, your work should be safe.
You could pull from origin (assuming remote is set):
git pull origin master
Or you could even clone the whole repo:
git clone https://github.com/project/project.git

In case your work is not there on Github, then it's either you never pushed your changes to Github, which you can't recover, or maybe the remote branches on Github were deleted as well. If you believe your work was deleted on Github, contact their support as soon as possible.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.