Simon Schug
26. April 2019
Version Control System for tracking changes in files.
You are nearly done 🍵️.
sudo apt install git-all # Ubuntu / DEB-based
sudo dnf install git-all # Fedora / RPM-based
You have 2 options:
Windows Subsystem for Linux (only Windows 10)
Use the standalone *.exe installer
You have 2 options:
Use brew (preferred 👍️)
brew install git
into the terminalgit
Use the *.dmg installer
git
Some useful commands to get started with Bash 🤖️
pwd
to print the working directorycd <folder>
to change the working directoryls
to list files/foldersmkdir
to make a new directorynano <filename>
as a simple text editorman <command>
reference manualSince this is your first time with git, tell it who you are 🙋️
git config --global user.name "Your Name"
git config --global user.email "youremail@email.com"
which text editor ✍️ you prefer
git config --global core.editor "nano"
and check ☑️ if everything is set up properly
git config --list
Creating a local git repository is easy 👯️
cd
git init
to initialize the repositorygit status
Where does git store its information?
Which files & folders will it track?
Commits with small changes are easier to read & review 💡️.
Let’s go through the modify-add-commit cycle 🌀️
git add filename
git commit -m "Meaningful commit message"
Use
git status
to monitor the current status of your repository. What tricks does it tell you?
Files you don’t want to track can be ignored 😑️
files
, folders/
or whole patterns *.dat
!filename
For common use-cases prefabricated .gitignore files most likely already exist, e.g. check .gitignore.io.
How can you see the tracked changes 👁️?
git log
shows the commit history of the repositorygit diff
shows changes within filesThe most recent commit is referred to by the identifier
HEAD
. What doesgit diff HEAD~2
do?
Branch operations are inexpensive in git 💸️.
Exploring an idea without changing the main project 💫️
git branch <new-branch>
to create a new branchgit checkout <new-branch>
git merge <new-branch>
What happens when both the master and the branch change the same part of a file?
Merge conflicts can arise when the same file is changed in multiple branches ⚔️
git log --graph
Resolving conflicts takes time, try to avoid them ✋️
Oops I made some bad choices, how can I go back in time? 🕓️
git checkout <commit-id> <filename>
git checkout -b <new-branch> <commit-id>
git checkout <commit-id>
. It will make you loose your HEADWhat is the detached HEAD state? How can you avoid it?
git init // Initialize local git repository
git status // Check status of working tree
git add // Add file(s) to staging area
git commit // Commit changes to repository
git log // Show commit logs
git diff // Show changes between commits
git branch // Create, list and delete branches
git checkout // Switch branches or restore files
Get a more elaborate git cheat sheet from GitHub Help.
To collaborate with others we need a remote 🌐️
Both offer many additional features like permission management, issue tracking, pull requests…
We use GitHub for the demonstration 🐈️
Create a new, empty repository on GitHub 👶️
git remote add origin <url>
git push -u origin master
Repositories should contain a license to handle copyright. .choosealicense can help you.
To synchronize changes in the local and the remote repository, you can use push & pull 🏋️
git pull origin master
to copy the changes into your local repositorygit push origin master
While
git commit
only updates your local repository,git push
updates the remote with the local changes.
With pull requests, you can propose changes to a repository and ask someone to review, pull and merge your contribution 💌️
git fetch
&& git branch -r
git checkout -b <branch> <remote>/<branch>
You are now ready to collaborate with others using git 🏁️
git clone
git pull
git add
git commit
git push
… so much more to discover 🔭️
You are prepared to discover those things on your own 🚀️