Git Q&A from a Women Who Code Cincinnati Workshop

Today I attended a Women Who Code workshop on Git. I have experience with both Git and GitHub, but there is always the potential to learn something new. We worked through a tutorial created by Code School that can be found at https://try.github.io/levels/1/challenges/1.

I was already familiar with everything in the tutorial, but the workshop was great because I got to ask some questions I had about Git as well as hear questions that other people asked. Below, I'll list some questions asked tonight and their answers.

Q1: Say, hypothetically, a developer makes two commits and wants to undo the first commit, but not the second. Is this possible?

A1: Yes, this is possible and would involve using the command git rebase. However, this can get pretty dangerous when working with other people on a project. The rebase command is a way to rewrite history. If you choose to use it, use with caution!

Q2: Git is a version control system. Does each version of a code project (for example, an Android app) get saved as a separate project on a computer?

A2: Version control systems save a DIFF file that shows how a version of the project is different from the previous version. If you are trying to visualize this conceptually, you can imagine having the first version of the project and then the combination of all the DIFF files gets you to the current state. In practice, the current state is stored as the default version of the project and you could get any previous state of the project by reversing the changes in the previous DIFF files.

You would not have to do this manually. If the project you are working with is on GitHub, you can go to the repository, then go to the list of commits. On the right side of the commits, you'll see buttons with a bunch of letters and numbers. Those are hashes. You can click on any of the hashes and then click on "Browse files" and you'll get all the code for that project at the time of that commit.

If you are working with a project on your machine that hasn't been shared on GitHub, there are tools you can use to easily access previous versions of the project.

Q3: On a Windows machine, what is the difference between the Windows Command Prompt and Git Bash?

A3: Git Bash can be a bit more convenient because Git Bash has Git on the path. All this means is Git Bash knows where to get the executable that allows you to run Git. If you are using Git Bash, the 'git' command will work by default.

This is not the case with the Windows Command Prompt. If you type "git" into the Windows Command Prompt, you will likely see a message about 'git' not being recognized. (Seeing this message is not an indication that something is wrong with your computer.) There are some settings that you can change so you can use the 'git' command in the Windows Command Prompt.

Another difference that I think is noteworthy is that the Windows Command Prompt uses Windows commands while Git Bash uses Linux commands.

Q4: When working professionally as a developer, what typically warrants creating a new branch? How do you choose a meaningful name for a branch? For example, does each team member each have one branch that they repeatedly commit to?

A4: It varies by team, but oftentimes a new branch is created for each feature. Sometimes, developers will add their initials to the branch name and this may help a team keep track of who is doing what.

Comments