Git: Working with branches

Git Branches

Introduction:

 

 

Git is nowadays a must tool when working on a project, concepts like versioning and backing up files while working on new improvements are a key that us as developers can't ignore.

Git is a version-control system for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for source-code management in software development, but it can be used to keep track of changes in any set of files. As a distributed revision-control system, it is aimed at speed, data integrity, and support for distributed, non-linear workflows.

Working with branches:

 

A branch in Git is simply a lightweight movable pointer to one of these commits. The default branch name in Git is master. As you start making commits, you’re given a master branch that points to the last commit you made. Every time you commit, the master branch pointer moves forward automatically.

We will need a starting point as a work envirorment, in this case, I've created a folder called R2D1.

Before we start: Make sure you're inside your folder.

To start any repository it is key to init git inside, so our first step is to execute on a command line envirorment the command git init.

Once it is started we may begin with the explanation:

As you may see on my screenshoot, I've initiated a new repository and added a few files with text inside and saved changes by using basic git commands(add & commit). 

Now let's create a new branch we're we'll make changes for future addition:


As it shows I've added some extra files on a new branch called test and when using git log It's already showing that one branch is ahead of master.

Now it will be as simple as a git checkout to our master branch and a merge with the branch ahead, but let's go further and observe what happens if we make similar changes on the master branch.

If you want to end it here:

Let's create a new branch and add a few extras and then add different ones to our master one.


As you may see, I've done a few changes to my branch(forgive my small mistake on one commit) and different ones to the master, as requested before.


If now we try a merge it will be impossible and git will tell us that we have issues regarding differences between files content.

The way to fix this issue is by solving this compatibility issues by removing ones or by entering the modified files and removing git indications.

Final git log:


 



Comentarios