Git Branches: Where have they been all my life??

Let’s quickly chat about Git and Github. And then we’ll get to those lovely Git Branches.

Now I learned a while while ago, just how important it is to use Git. It’s a form of version control that developers use for their code. It’s important because they can keep track of when certain changes were made, and (god forbid) they can go back to an earlier version of their code if an error occurs with a change. Also Github is important because it acts as a backup for any code projects, while making it really easy to share projects with team members or just the general public.

Unfortunately I haven’t been using Git for about 2 months. First because I am just out of practice and haven’t been using the command line like I should be (ideally I’d be using it daily just to stay familiar..). Second I have not been on my computer, since the screen is broken. I have been on my husband’s home computer (which has a dual monitor set up, it’s dope). So I needed to download Git and reset up everything on his computer. So no excuses! I’m doing it now!

Now let me introduce a project I’ve been working on and why I would’ve use Git Branches from the beginning had I understood it.

I have this “digital bulletin board” project that I have been working on for a church. It’s a website that will be projected on the monitors in the vestibules at church. The first draft of this is just a javascript slideshow, that the staff at church can upload photos too to keep it current. The church already posts similar slides (photos) on their website and their actual bulletin, so this is just an extension of that and should be fairly easy to incorporate into their communication routine.

The javascript slideshow is running, and it works. But as a developer, I know how much better it could be. My wishlist is that I’ll write code that’ll make any sized image uploaded look full size on any sized monitor. The tv screens they are using are not all the same size, since most have been donated, so making everything responsive is very important!

Most recently I am developing a “welcome slide.” I want this to look very professional, to fill up the whole screen, and ideally have all dynamic content, meaning that I won’t have to go in and update it every week. I’m thinking it’ll post the current date, a current scripture reading, current mass times, etc. This same design is going to be used in the parish office, the church office, and the gym, so once I get something I’ll like, I’ll start tweaking it and adding different functionality for different purposes.

While developing this “welcome slide,” I have been creating different versions of my slideshow project, so that I can make changes without messing with my project code that already works. This is basically exactly what Git Branches are for! Instead of creating a new file every time and copying and pasting when something I works, I could create a new branch in Git, experiment until I have code I like, and then merge the branches to commit that code to the main project!

Seriously where have git branches been all my life?

Below I’m just going to document my steps using Git:

First I’m going to create a repository (since I haven’t been using Git already–oops!)

Create Repo in Git

 

  1. Using command line (terminal-Mac) navigate to the correct directory
  2. Initialize repo: type git init in terminal to create an empty Git repository (/sites/hs/slideshow)
    1. type git status just to make sure you’re in the right place and to see all the files available to commit
  3. Add each file individually by name with git add (+insert name!) OR use git add . to add everything listed in red
    1. I’m going to add individually because I only want to save my original slideshow project
    2. type git status to confirm you’ve add everything you want for this commit
  4. Time to commit changes!
      1. type git commit -m “insert your own comment here!” obviously writing your own appropriate comment here

     

    1. type git status just to make sure your files were committed. My working tree will not be clean since I did not commit all of my files

Now that my repo is set up, I want to start working on my more experimental code. So I am going to create a branch to do so.

Create a branch in Git

  1. Create and check out a new branch on the command line
    1. type git checkout -b welcome (welcome is just the name of my new branch—feel free to sub your own name!)
    2. type git branch just to confirm what branch you’re working in
  2. Use open . to open this branch in finder
  3. Now you can make whatever changes you want to your files and it will only affect this branch and not the master branch
    1. type git branch whenever you need to confirm you’re in the right branch
    2. use git checkout master when you need to switch back to the master or git checkout welcome to switch to the welcome branch
  4. Whenever you’ve made a significant change or are reaching a stopping point, remember to commit changes!! That’s the whole point of this!
    1. remember to first git add the files that have changed
    2. then git commit -m “comment about change” to commit the change
    3. and for peace of mind git status to make sure your working tree is clean 🙂

No comments

Leave a Comment

Your email address will not be published. Required fields are marked *