Loading...
 
JoiWiki » Developer » Applications » Git » Git Concepts and Setup » Git Basics Git Basics

Git Basics

Git Basics

Git is a tool long since used by developers to keep track of their code changes, it allows them to easily see when and what any particular change was and share those changes with remote repositories. I should’ve come to git years ago and now that I’ve started to use it professionally I’ve no idea why I didn’t take the time because it makes keeping track of multiple projects over multiple computers a breeze!. Until now I’ve used Microsoft’s Team Foundation Server services and they were great, going from a world where I was manually moving project folders between pc’s and cloud storage and simply remembering where the latest changes were was wonderful but it had problems; one of which was convincing other developers to go through the setup process to add my repositories, another being that it was principally for visual studio projects. Git on the other hand is lightweight, simple to execute commands with and makes stepping through change sets a casual affair.

What is git?

Simply, git is software that tracks the state of a set of files at different times (through the use of commits) and saves those changes so that they can be interrogated or called back. These changes are stored in a hidden .git folder in the directory being tracked and any files in that folder or any subfolder can be added to git.

How do I talk to git?

Git is very powerful and was initially written to track files by Linus Torvold when developing linux (Wiki) so the main way of communicating with git was the linux Bash console and even now when installing git on a windows PC by default you’ll install a bash shell emulator. These days there are numerous graphical user interfaces for every operating system in both the paid and free categories, but as these can hide commands and functionality most will also have a terminal open when working with git as all available functionality can be used. Because of that my notes will be based on the use of the command line rather than any particular GUI.

So how does it work?

I’ll go through the setup and use of git repositories in another article but in a nutshell the structure of git is this: as mentioned above when a folder is added to git a .git folder is made to keep track of the contents, this folder forms your local repository and is tracked with a main branch called master. As your main project is tracked in master when you want to develop functionality on that project you would want to create a specific branch so that other feature developments can have their own branches. This way all of your changes are kept isolated whilst you work on them and the master branch is not affected until you’re ready to merge your changes back in to be picked up by other feature branches. At this point I’ll mention ‘origin’, which is the default alias given to a remote repository, services which offer online git hosting are BitBucket ant GitHub, these services let you track your master and/or other branches and share them between machines or users. One common implementation of git is to use the remote to handle merging feature branches into the main branch so that developers only ever pull into their local master branch to pick up changes and never push to the remote master.

Feature branch development

So if you want to track a project with git you’ll generally:

  • clone an existing remote repository onto your local machine which will have code in it already or it will be empty (so you’ll need to set up some files into your master). This means your master is fully up to date.
  • Branch off of your local master and develop your feature or functionality.
  • Once you’re happy with your code commit it to your branch with a message.
  • Update your local master with the remote repository (origin).
  • Update your branch with these changes and deal with any conflicts that may arise in the code.
  • Push your branch to the remote repository (origin)
  • Raise a pull request if necessary (this gives other developers the chance to review your changes and suggest amendments or give praise)
  • your feature branch is merged into the remote master (origin) for other developers to pick up
  • you’ll update your local master with the updated remote (origin) and you’re done!

I’ll go over how to perform these actions in another article but those are the basics of git. If this hasn’t hit the nail on the head for you there’s lots out there to read on git and how to use it, I personally recommend Pro Git as I’ve been using that extensively myself and it’s free.

Created by JBaker. Last Modification: Saturday December 22, 2018 16:36:05 GMT by JBaker.

Developer