Category Archives: Git

My Git Workflow – Beginners

So for a year, I’ve been trying to learn to use Git and Github effectively. It hasn’t been easy for me. It seemed like my brain just wouldn’t work that way. However, I feel a lot more confident recently, and I’d say the biggest steps to my improvement in Git usage (apart from just not giving up) was reading “The Git Book”. Something about this really helped things click with me, and I can’t recommend it highly enough. I’m not even finished reading it, but already I am using a work flow in Git and not being so scared.

It also helped to keep at it, using it in a few different ways with a few different people – yet again the super helpful and patient Ruby community in Sydney comes to the rescue.

Here I am just going to record the current steps I am using in my Git workflow, so as not to forget.

Branch Structure

I am having ‘master’, and not doing anything on it.

I have a ‘develop’ branch, from which I branch to do each little bit of work, and then merge each one into ‘develop’ before I move on.

My branches off ‘develop’ are called things like ‘feature/view-refactor’.

Git Steps

Starting on ‘develop’ branch

  1. $ git branch feature/feature-name #create new branch
  2. $ git checkout feature/feature-name # move to new branch
  3. $ git push -u origin feature/feature-nam #this makes sure my remote has this branch to track
  4. Do some work
  5. $ git diff # Look at the work I’ve been doing.
  6. $ git add
  7. $ git commit -m “try not to leave a useless message”
  8. $ git push
  9.  Then in GitHub I did a pull request from that feature branch to develop
  10. Merge  while in Github
  11. Github lets you delete the remote branch
  12. $ git checkout develop #On my machine, switch to the ‘develop’ branch
  13. $ git pull #pull changes from origin
  14. $ git branch -d feature/feature-name #deletes the branch on my computer
  15. $ git fetch –prune # so that on my machine it removes mention of the old branches on the remote

 

Leave a reply

GitHub Fork and Pull Requests

The Udacity CS101 study group is going well, and I’ve stuck with it – though I’m sure this is mostly to do with doing it as a group. Some of the problems are REALLY hard, and I don’t know if I would have persevered on my own.

Learning To Code Tip #2123: If you do a computer science 101 course online – consider a study group to help you through it!

As the problems are getting harder, our group organiser has created a git repository for it, so that we can get help/hints outside of class (since not all the problems have solutions). I loved this idea because I desperately need more practice using Git. So here are my steps on how to contribute to a repository through forks and pull requests:

Contributing to a repository on Git with Fork and Pull Requests

1. Go to the repository you want to fork from and hit the Fork button
2. Go to the fork of it in your own repositories now and copy the HTTPS
3. In your terminal run the following with that https pasted in

$ git clone https://github.com/username/

4. Move into that directory, then add the upstream (original) repository if you want:

$ git remote add upstream https://github.com/whatever-the-original-one-is
(This gives the shortcut name “upstream” to this repository, so you don’t need to use the URL)
5. Whenever you want to get changes made to the original

$ git fetch upstream

7.  This will merge any changes fetched into your own files

$ git merge upstream/master

6. When you want to push up your own changes to your own remote repository, i.e. not the one you are forking from, you need to go

$ git push URL_of_your_remote_repository

If you want your changes to be considered for adding to the original repository make a pull request:

7. In Github, go to YOUR repository and click ‘Pull request’

8. If you have been good enough to be using branches, switch to your branch.

9. Click the green compare and review button

 

 

4 Replies

Git Terminology

Git Version Control

I continue to have a hatred of Git and GitHub purely due to my own ignorance and lack of comprehension. Let’s try to overcome this prejudice with a bit of education!

  • master - the repository’s main branch. Depending on the work flow it is the one people work on or the one where the integration happens
  • clone - copies an existing git repository, normally from some remote location to your local environment.
  • commit - submitting files to the repository (the local one); in other VCS it is often referred to as “checkin”
  • fetch or pull - is like “update” or “get latest” in other VCS. The difference between fetch and pull is that pull combines both, fetching the latest code from a remote repo as well as performs the merging.
  • push - is used to submit the code to a remote repository
  • remote - these are “remote” locations of your repository, normally on some central server.
  • SHA - every commit or node in the Git tree is identified by a unique SHA key. You can use them in various commands in order to manipulate a specific node.
  • head - is a reference to the node to which our working space of the repository currently points.
  • branch - is just like in other VCS with the difference that a branch in Git is actually nothing more special than a particular label on a given node. It is not a physical copy of the files as in other popular VCS.

Courtesy of this article here

Also – someone told me that…

Branch is like “Save As”

…which might be helpful to remember

And finally, here is yet another ‘beginners guide’ to Git 

3 Replies

Love Hong Kong, But Missing My First GA Lessons

Hong Kong

 

I am currently travelling and working in Hong Kong and Shanghai – which I have been looking forward to all year, and am loving. BUT, unfortunately, this is also the week that my General Assembly course started (Back End Web Development).

So, I am missing the first two lessons, and originally I thought that this would be no big deal because maybe it would cover some very basic stuff, which I already knew – but of course the basic stuff they are covering is GitHub! My nemesis! I understand that GitHub is amazingly useful – but I can’t wrap my brain around it, and wished that I didn’t miss this lesson, of all lessons.

Our super helpful tutor has, however, provided us with lots of references to help us with it – so I am trying to combine work with study (not only this weeks lessons, plus homework, but the prep work too! Agghh! Already behind!) and also not spend all my time in these amazing cities indoors. This would all have gone a lot smoother had I not also just discovered The Walking Dead (yes, three years behind as usual).

Ok, so these are the extra things I have learned from the first weeks course in BEWD (Back End Web Development).

Command Line

My tutor recommended this tutorial for learning the basics of the Command Line.

I think this is great because it lists and explains all the main commands, and I’m sure I’ll use it many times in the future when I need to understand how to do something in Terminal. BUT I was hoping for some simpleton explanation of what they are talking about when they say “BASH” or “Shell”. Having said that, I know there are a million explanations online about that…

The writer also reinforced that you shouldn’t just get random advice from idiots on the internet, in case they are getting their fun by making strangers wreck their computers…I am so naive I never thought of that, but I assume StackOverflow would weed out those kind of things, so I will keep using it.

Git Cheat Sheet

Look at this awesome Git cheat sheet.

Even though it is a cheat sheet, they found space to put in some basic explanation, which I need:

Git is a free & open source, distributed version control system …GitHub is the best way to collaborate around your code. Fork, send pull requests
and manage all your public and private git repositories….Heroku is a cloud application platform that supports a number of different programming languages…

The rest of it is extremely useful, and if I had a desk with a wall, I’m sure I would print it out and put it up there. (Maybe I should get a desk, and a wall next to it…?)

(Actually, I just downloaded it, and then used my command line skills to move it into my learning folder. Tricky!)

Git Videos

Here the tutor recommended these introductory Videos for Git

I have a lot of trouble with getting my head around Git (and GitHub), and even though I have already written about this on my blog before,  it still doesn’t stick in my head.

These are great introductory videos to Git – explaining the concepts, and some easy command line keywords – but I still find the workflow confusing, and also the concept of where all this historical information is stored on my computer, and how I would access it. I need more lessons obviously.

Also, I wish that video had a transcript, because at some points I wanted to repeat, repeat, repeat to try and understand, and rewinding is just annoying.

Practising With Git

Finally, our tutor recommended Code Schools ‘Try Git’.

I like being able to actually try things, so I liked this tool. It also introduced me to a few new keywords which helped me better understand the point of git.

$ git status  which I hadn’t used before, and it is really useful to help you understand. I was using this after every operation!

$ git log – nowhere else had yet explained to me that I could use this to read the logged changes. This was an essential question I had – why am I recording all these changes if I can’t go and look at the history!

$git diff – to see the differences between versions.

$git reset – to remove things from the staging area.

Anyway –  obviously all these commands are in that excellent git cheat sheet – this tutorial just helps you have a go at using them.

The only thing I wish was different about this set of tutorials is I wish they had explained more about what the output of all these commands meant.

 

 

 

Leave a reply

Pushing to GitHub

GitHub

At Rails Girls Brisbane we created a little app and at the end of the day pushed it up to GitHub.

Because I am sure I will need to do this a lot (for example, right now, as I have just bought a new laptop and I want to get all my stuff off of this old one), I have decided to write down the notes I took from Rails Girls, to make sure I remember the process.

Ok, so

Pushing to GitHub

Step 1 – Navigate to the appropriate directory in your terminal, so that you will be pushing up the right files.

Step 2 – Make a new empty git repository by typing this into Terminal
$ git init .

Step 3 – Add all files
$ git add .

Step 4 – Check status of all those files
$ git status

Step 5 – Commit and Describe your changes
$ git commit -m"Write whatever message here to describe the changes you made"

Step 6 – Create new repository in GitHub
Go to Github, click on new repository, then copy the http URI

Step 7 -
$ git remote add origin https://whateverthaturlyoucopiedwas

Step 8 – Push up to GitHub
$ git push origin master

When making changes in the future, you can just go

$ git add .
$ git commit
$ git push

Leave a reply