Git is a free versioning software; each project is a repository. This tool enables collaborative work on the same codebase. It is notably used by the open source platform GitHub.
Vocabulary Repository A place where code versions are stored. Repositories can be compared to projects. Commit A version of the project at a given point in time. Push Sends one or more commits to a repository. Pull Downloads commits from a repository. Fork A fork allows anyone with access to a repository to clone it and make their own modifications. Tree Contains a commit, describes the source tree structure; a tree object points to multiple parent commits. Branch Since each commit knows its parents, it is possible to have two teams working on two different branches (the main branch is master). This allows creating two parallel versions of the project. The two branches can then be merged to combine everyone’s work. Example: a dev branch and a production branch (master). Once a commit on the dev branch is validated, the branches are merged and the main branch gets the new features. Merge The fusion of two branches. Stash A local storage space containing modifications that have not yet been committed. Useful for example when switching branches with pending changes. Rebase Allows rewriting part of the commit history. Cherry-pick Allows adding a commit to another branch without merging the entire branch. Essential Commands Initialize a git project git init List configuration globals git config --list Configure username git config --global user.name "your_name" Configure email git config --global user.email "[email protected]" Status of modified files git status First commit git add . git commit -m "initial commit" Subsequent commits git add path_to_my_file git commit -m "commit message" Amend the previous commit git commit --amend View commit history git log View commit history (one line) git log --oneline View branches as a graph git lg View differences from the last commit git diff Restore a file to a previous commit git checkout <commit> <file> Revert to a previous commit (adding modified files to staging) git reset <commit> Revert to a previous commit (removing files from staging) git reset <commit> --hard Create a reverse commit git revert <commit> Rebase a branch git checkout <commit> git rebase master Interactive rebase git rebase -i <commit> Interactive rebase works with a scripting system. When running the command, a new window opens where you can perform these actions on each commit:
...