Git is a tool that offers a version control system in order to record changes to any type of file, over time, so that it's possible to recall specific versions later.
The following terms are used:
These are the steps to install Git:
gitpackage through Synaptic Package Manager;
user.emailwith the commands:
git config --global user.name "<user>" git config --global user.email "<email@example.com>"
Configuration settings can be checked with:
git config --list --show-origin
It's possible to cache username and password in order to avoid their input every time a connection to the remote is established. The cache mode can be set to keep credentials in memory for a given period of time in seconds:
git config --global credential.helper 'cache --timeout 7200'
These the steps to create a new repository in one's Git server:
The steps below are intended when the remote repository is already created and it contains a project.
git clone https://<user>@<git-server>/<user>/<name-repo>.git
name-repo, containing the copy of the remote repository.
The steps below are applied when there is some files, in the local repository, ready to be pushed to the remote repository.
git add --all
git add <name-file>
Before commit the files it's possible to do as many changes as necessary to them, and when they are finally ready, run the
add command again.
git commit -m '<your message here>'
git push origin master
git push origin <name-branch>
To force files to be pushed in the remote repository, overwriting the existing ones:
git push -f origin <name-branch>
.gitignore file specifies the directories or the files that Git should ignore.
.gitignorefile within the root directory of a local repository.
# ignore these directories and their content <dir> # ignore these files <path>/<file.ext>
The following command is used to inspect the status of the local repository respect to the remote one.
To see if there are any difference between the working directory and the HEAD:
git diff HEAD
git log --oneline
git show --pretty="" --name-only HEAD
To fetch changes from the remote repository and merge them into the local one:
To force files to be pulled in the local repository, losing changes not already pushed in the remote one:
git fetch --all git reset --hard origin/<name-branch>
Branches are just pointers to commits, this means that Git doesn't create, and shouldn't be created, a whole new set of files or folders.
The following steps are applied when we want to work on a separate branch different from the mainly one, called
git branch <name-branch>
git checkout <name-branch>
To know in which branch we are now:
The next steps are intended when the work on a secondary branch is ready to be imported in the mainly one.
masterbranch, switch to this one:
git checkout master
git merge <name-branch>
git push origin master
If merge conflict happens it must be manually solved.
<<<<<<< HEAD changes made in master ======= changes made in <branch-name> >>>>>>> <branch-name>
To delete the branch:
git branch -d <name-branch>