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:
You have 2 options:
Use brew (preferred 👍️)
brew install gitinto the terminal
Use the *.dmg installer
Some useful commands to get started with Bash 🤖️
pwdto print the working directory
cd <folder>to change the working directory
lsto list files/folders
mkdirto make a new directory
nano <filename>as a simple text editor
man <command>reference manual
Since this is your first time with git, tell it who you are 🙋️
git config --global user.name "Your Name" git config --global user.email "firstname.lastname@example.org"
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 👯️
git initto initialize the repository
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"
git statusto monitor the current status of your repository. What tricks does it tell you?
Files you don’t want to track can be ignored 😑️
folders/or whole patterns
For common use-cases prefabricated .gitignore files most likely already exist, e.g. check .gitignore.io.
How can you see the tracked changes 👁️?
git logshows the commit history of the repository
git diffshows changes within files
The most recent commit is referred to by the identifier
HEAD. What does
git diff HEAD~2do?
Branch operations are inexpensive in git 💸️.
Exploring an idea without changing the main project 💫️
git branch <new-branch>to create a new branch
git 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 HEAD
What 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 masterto copy the changes into your local repository
git push origin master
git commitonly updates your local repository,
git pushupdates 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 branch -r
git checkout -b <branch> <remote>/<branch>
You are now ready to collaborate with others using git 🏁️
… so much more to discover 🔭️
You are prepared to discover those things on your own 🚀️