Pitch your project

Random text


By admin Category Uncategorized, Posted November 13th, 2015
Git and Command-line

What is Git?

When developing in a team it’s important to know who’s doing what and which versions are made by who. A system that helps you to keep control over your project is Git, a distributed revision control system. When using this system everybody has their own full copy of the repository and its entire history. It’s possible to work on this copy without a network connection, since most commands operate locally. Using this system it’s easy to look back in the history of the project to see which changes have been made by who.

How does Git work?

Git is different from other VHSs because of the way it thinks about files. Git makes some sort of a snapshot of the files in a version. By doing this Git doesn’t have to copy files which aren’t changed, it can just link to the original file. Also this system makes it very easy to see which files have changed in a version.

Because Git works with branches, I like to compare it to a real tree when explaining it. The original branch will be the one which, when all the work is done, wil be put online. This branch is like a tree trunk since all the branches will be ramifications from this branch. From here on every developer can make its own branch where they can work on their own version. When all versions on the different branches are finished they can be merged back on the original branch.

Tree structure GIT source

Lets start working with Git!

To start working with Git you have to download and install Git. You can read more about this here. If you start a project you have to make your own repository, if you want to contribute to an existing project you need to fork a repository.

After doing this you have a copy of the project on your local system and you can start add files and making changes in the existing ones.
TIP: Make sure you always discuss who will be working on what file and which name conventions you will use to prevent errors.

How to tell Git what to do?

To communicate with Git I use my terminal, since I’m a Mac user, but every command line will do. You can also use programs like SourceTree depending on what you’re used to of prefer. My explanation will be about command line.

To start working you go to your local copy of the project and you open command line for this folder. To see your copy working in the browser you type the command grunt. Your browser will automatically open the project in your browser. Before you can start making changes you have to check if you are in the right branch. You can do this bij typing the command git branch. After this command you will see a list of all your local branches, the active branch will be green with a * in front of it. If you want to create a new local branch, you type the command git branch “name of new branch”. When you want to switch between existing branches you type the command git checkout “name of branch you want to switch to”. In case you want to create a new branch and directly switch to it you type git checkout -b “name of new branch”.

Now you are in the right branch, you can start making changes in your copy. When your done you have to put it online to the repository. To do this it’s important to understand the 3 stages of Git: working directory, staging area and repository. The changes you have made are in your local copy, also called the working directory. If you want to put your work online you, first have to add it to the staging area before you can commit it to the repository.

The three stages of GIT source

To check which files are changed and have to be put to the staging area you type the following command in your command line: git status. When you have made all the changes, or want to make a backup of your local work you have to add the changed files to the staging area by typing git add “file name”. When you type git status again you will see which files you have added to the staging area. When all the files are in the staging area you have to commit it. You do this with the command git commit -m “message”. The last step is to push the files and the message to the repository with the command git push.

When everyone is done and all changes are made and you might want to merge a couple of branches into one branch. To do this you have to go to the main branch and type the command git merge “name branch to be merged”.

Basic commands for GIT

git branch                                  Check in which branch you currently are
git branch "name newbranch"                 Make a new branch
git checkout                                Switch between branches
git checkout -b "name new branch"           Make a new branch and switch to it
git status                                  Show which files are changed/added to
                                            your branch
git add "file name"                         Add a file to the staging area
git commit -m "message"                     Commit a message to the file in the
                                            staging area
git push                                    Push both the files and the message to
                                            the repository
git merge "name branch to be merged"        Merge branches

Posted by Amanda de Rijk

Leave a Reply

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