Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

James Barrett
James Barrett
13,253 Points

Git: Revert or new branch?

Hi there,

I recently finished a project which has a few defects in. The problem that needs to be fixed lies on a branch which has been deleted remotely.

Should I just create a new branch called 'fixes'? Or is there another way around this? The main aim here is to brush up on my Git and GitHub skills :P

If you need me to provide more information then please let me know. :)

Thanks, James.

1 Answer

Kristopher Van Sant
PLUS
Kristopher Van Sant
Courses Plus Student 18,830 Points

Good question James!

You mentioned that you deleted the branch remotely, so does that mean you still have it locally? If so I think you might be able to make the change on the local branch and push it up again.

If not, you could try restoring the deleted branch and making the changes. Which, if you're looking to brush up on some skills, might be something worth learning how to do.

Otherwise, if it's your own personal project I don't see anything wrong with creating a new branch. If you were working with a team there would more likely be specific guidelines on how to handle situations like this.

Hope that helps some! :)

James Barrett
James Barrett
13,253 Points

Hi Kristopher,

Thanks for your answer.

I think I might have confused myself a little bit. I have followed a simple workflow of <feature-branch>... push to <master> branch and git branch -d the_branch...

Does this mean I have deleted it remotely or locally? And if is locally, my question description would change to "The problem that needs to be fixed lies on a branch which has been deleted LOCALLY.". :P

I look forward to your response. :)

Thanks, James.

Kristopher Van Sant
Kristopher Van Sant
Courses Plus Student 18,830 Points

Ah, ok. So just to clarify again, once you're done with a branch you merge it into master(local master), and then do you push it up to Github(remote master)? Or are you just using git alone? Github would be your remote repository and what you do on your computer would be in your local repository.

Github = remote

Your Computer/Dev Environment = local.

And after you push it you delete it. Hooray for cleaning up your branches when you're done with them! A lot of people forget to do this.

So it sounds like you deleted the local branch, you can still restore that branch if you wanted and make your changes. But if you've made changes since then that you want to keep it might complicate things.

Personally, I think the easiest thing would be to create a new branch and fix the issue there.

If you're using Github and want to play around there, you could make a new issue explaining the problem and where it's at, what line, what branch it was on etc. And then after you've made the change, when you commit the branch(before merging and pushing) you can reference the issue in your commit comment and use a keyword to close it! https://help.github.com/articles/closing-issues-via-commit-messages/ Then when you push it up to Github it will automatically close the issue for you! I love this feature, so satisfying to have an issue closed via commit messages.

James Barrett
James Barrett
13,253 Points

Hi Krisopher,

Thank you for the reply, that has cleared a lot of things up!

Ok, so currently I have two issues open in a repository: https://i.gyazo.com/8493fc0100133e86a0ce9b746958d53a.png

How exactly would I go about removing issue #1 if I created a new branch called 'fixes'?

Here's what I think would work: 1.) Make changes 2.) git add . 3.) git commit -m "Fixes #1

After committing, the power of Git will remove that issue from GitHub automatically? Or would I have to git push origin fixes first?

Thanks again for you help, James.

Kristopher Van Sant
Kristopher Van Sant
Courses Plus Student 18,830 Points

Awesome! So happy to help.

You've just about go it! So yes, your first three steps are correct. You can still add a little more information in your commit message if you wanted to, but then just make sure you include that "Fixes #1" or whatever keyword you want to use. And yes you still need to push it up to Github for the magic to happen :)

So your workflow might looking something like this....

  • Step 1 - git checkout -b Fixes (create a new branch called Fixes)
  • Step 2 - Make any changes needed
  • Step 3 - git add .
  • Step 4 - git commit -m "message about what you did and changed and maybe why. This fixes #1"
  • Step 5 - git push origin Fixes
  • Step 6 - Merge branch into master through Github or locally, though git

OR... alternative workflow after step 4, if you want to go ahead and merge the changes into master sooner than later

  • Step 5 - git checkout master (switch to master)
  • Step 6 - git merge Fixes (merge branch with master)
  • Step 7 - git branch -d Fixes (delete branch)
  • Step 8 - git push origin master (push to remote master)

Does that make sense? Let me know how it goes!