A presentation to accompany the lecture held on 10/25/2020.
Google Developer Students Club - https://dsc.community.dev/university-of-belgrade-univerzitet-u-beogradu-univerzitet-u-beogradu/
2. What is Git?
Git is Version Control System (VCS) responsible for managing changes in
files and keeping historical copies.
It was created in 2005. by Linux community in order to provide
collaboration between a lot of geographically distant programmers who
worked on the development of the linux kernel.
Git is now one of the most popular version control systems out there and
is used in millions of projects.
It is a free open source system available for installation on Unix based
platforms, windows and macOS
3. GitHub
It was created in 2007.
Web-based hosting platform for software development and version
control using Git.
It provides access control and many other features such as bug tracking,
task management etc.
Commonly used as a host for open source projects.
There are also features characteristic for social networks ( followers,
feed…).
Over 50 millions of users in this moment.
4. Elementary commands
git config
command for setting information such as name or e-mail address
option --global for setting information globally for all repositories
git init
initializes git repository locally
git clone <repo_url>
command for cloning remote repository from hosting service
5. git add <file_name>
command for adding specified file to the list of changes to be
committed (staging area)
option --all for adding all modified files to the staging area ( .gitignore
file for exceptions )
git commit
creates a new commit
commit message is required, it can be specified in command by option
–m followed by message text
message should contain all of the relevant information about
commit!
option –a for committing not just staged but all modified files
6. git status
displays differences between current state and last commit
displays all changed files including their states ( untracked, modified,
staged ), files specified in .gitignore are not shown here
git log
lists the history of commits in the current branch
unique commit identifier
who made this commit
date and time
commit message
additional information
there are many options for displaying commit history in different
formats
7. git diff
shows all modifications in tracked files ( in modified state )
option --staged for showing differences in staged files
git commit --amend
updates previous commit
in the background it creates completely different commit with different identifier
which should replace the previous one
8. Branches
Creating separate branches for different features
Making changes in code independent of the main branch
Switching from one branch to another
Merging
9. Branch commands
git branch
existing branches are listed, current branch is highlighted and marked
with an asterisk
git branch <new_branch_name>
command for creating new branch with given name
option –b for switching to new branch
git checkout <branch_name>
command for switching to specified branch
11. Moving through history
Git allows you to retrieve an earlier version
git checkout <commit_id>
return to the version specified by the commit identifier
Instead of the previous command we can refer a commit using offset
relative to the last commit in branch or HEAD pointer
git checkout HEAD~2 ( git checkout HEAD^^ )
These two command are equivalent, in this example offset relative to
HEAD pointer is 2
12. Working with remote repositories
git fetch
this command copies the commits done in the remote repository to
the remote branches and now they are reflected locally
git pull
fetches the remote branch and automatically tries to merge it to the
current local branch, actually we have fetch and merge in single
command
git push
makes our local changes visible in remote repository