Introduction to GIT

Introduction to GIT

GIT is a decentralized version control system, created by Linus Torvalds (yes, the same creator of Linux).
It provides a complete command line tool to handle either local or remote repositories.

I highly recommend following the documentation, https://git-scm.com/book/en/v2, mainly the first two chapters that not only would help you understand git graphically, also to get an introduction to the basic commands.

Im not going to explain basic commands here, my idea is to provide an overview and basic concepts in the git universe.

Local or remote repository

People coming from SVN or any other centralized version control system, are used to have a server dependency, git doesn’t.
You can be in the middle of an african jungle, with no wifi, no 4g, not even a phone with you, don’t worry, you can grab your laptop and get ready to work with git.
The command line tools let you create local repositories for the working directory, and you will be able to do any operation not involving remote servers as commits, merges, tags, branches, and much more.
I will explain below how ‘remotes’ (remote git repositories) work, by now Im just going to mention that you can sync up your local repository with a remote repository in Github, Gitlab or any other git server.

Untracked, not staged and staged changes

There are 3 different states for every file in your working directory, Im going to quickly describe each state:
Untracked: new files that are not tracked or not being included into your git repository, if you want to start tracking those files with git just run git add [filename]
Not staged: files that were committed to git in the past and now git detects new changes in those files, you can move them to the stage using git add [filename] or revert local change and go back to the original file using git checkout [filename]
Staged: changes ready to be committed, either new files, removed files, or new changes over existing files, git commit -m"[message]" will create a new revision with your staged changes.

Branches and tags

Git is based on commits, an either branches and tags are references (or pointers) to specific commits. You can create a branch whenever you want, that branch will point to the HEAD (where you currently stand), then you can start moving forward in your tree adding more commits and your current tracking branch will be updated and pointing to the last commit.
Tags are similar in the way that can be created and point to the HEAD (or a specified commit) but are not intended to be moves across different commits, are considered more like labels conceptually.

create branch:
git branch [branch-name]

create tag:
git tag [tag-name]

Remotes

Ok, it's time to put our work in a safe place, we need to sync up our local git repository with a remote git repository.
Remotes are external repositories that we would want to use mainly to keep our work safe in a remote server, some of the most important providers are Github and Gitlab, both with free and paid plans. But remember git is open source and you can run your own server, in fact you can have another local folder as your remote, remember that a git repository can be stored locally, your working directory is a git repository too.

In order to add a remote to your working directory just call,
git remote add [remote-name] [remote-url]

Then git pull and git push are the basic commands to sync up your local and remote repos.

Organize your project using OneFlow

This is not something you are going to use if you are starting using git on these days, but it worths to mention OneFlow as an organized branching workflow you would like to use in a company with your team.
More details here, http://endoflineblog.com/oneflow-a-git-branching-model-and-workflow

UI Tools

Here I provide some apps people use for git, anyway I always recommend using the command line tools as long as you can to better understand how git works, some of the tools mentioned below do lot of stuff behind the scene and sometimes we get unexpected result or errors and the UI will not let you solve them easily, you will end using the command line in those cases.

SourceTree

https://www.sourcetreeapp.com
by Attlasian, this is a complete application with a branching tree view, lot of configuration options, easy way to configure ssh, diff viewer, and it has most of the options you have available in the command line tool.

Github Desktop

https://desktop.github.com
Open source app developed by the same Github team (now owned by Microsoft), it's a pretty basic application, unfortunately the current version has removed the branching tree view, so do not expect too much from this app, just the basic to inspect branches, commits, diff, and do some basic operations.


Share Tweet Send
0 Comments
Loading...