This tutorial is for starting to use the version control software named Git. According to ProGit (super recommended material, available for free here: book)
Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later
Version control is a fundamental tool to keep track of the changes of any type of digital content. This applies naturally to text documents, and the most common application of version control is for software developing.
In order to keep track of progress and have an idea of the different versions your software is adopting through time Git provides you with many utilites and at relatively low effort.
Main concepts and terminology
We will refer as repository to a project's version controled files. This can be a local directory as well as a remote server directory.
Each time we are doing version control of a repository with Git we are tracking changes in the repository by using time snapshots of the repository state. So, in short Git can be understood of a stream of snapshots.
Distributed version control
Git is a distributed version control system. This means that each Git repository is a complete mirror of the repository's history. Every time we make a checkout we copy the full we are doing a full backup of all the snapshot data history.
This also brings an important feature to Git: every operation is done locally. At some point we will push our changes
Info | ||||
---|---|---|---|---|
| ||||
When you clone a repository you are again, copying the entire history. The same applies to GitHub repos, so, in few words you have multiple independant copies of the full version history. |
Versioning your files
Let's start running some commands and using Git.
Creating a repo
Let's imagine we have a bunch of files in the following manner:
~$ ls Devel
project
~$ ls Devel/project
hello_world.py
foo.py
bar.py
Now we want to track the progress of the python files. So we move to the working directory and run the following command:
~$ cd Devel/project
~$ git init
Initialized empty Git repository in /home/bruno/Devel/project/.git/
This will create the git repository. We can confirm this by checking that we have the following files in the directory
~$ ls -la
hello_world.py
foo.py
bar.py
.git
After this we can run a super useful command, that helps us understand the current status of the repo:
~$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
bar.py
foo.py
hello_world.py
nothing added to commit but untracked files present (use "git add" to track)
So, running this will allow you to find out where are you standing and which files are being tracked.
Tracking files
To track a file we just have to run the add command:
git add hello_world.py
This will stage the files to the so called index. The index is what the repo actually contains, it means that every file in this index is going to be versioned.
When we have files in the index we say that they are staged. At this point running a status will yield the following:
~$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: hello_world.py
Untracked files:
(use "git add <file>..." to include in what will be committed)
bar.py
foo.py
As it can be seen from the ouptut, we have our hello_world.py file that now is ready to be commited.
Commiting is the concept of making an impact on the repository history. This is, taking a snapshot of our code.
Artículos Relacionados
Filter by label (Content by label) | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Page Properties | ||
---|---|---|
| ||
|