Note This repository covers materials associated with the
Git & GitHub Workshop
authored by Filip J. Cierkosz. The resources found here are designed to help to understand and learn how to effectively useGit
andGitHub
.README.md
of this repo complements the concepts introduced in the slides.
- What is
Git
? 🧐 Git
Installation 🛠️LCL
: Essentials Cheatsheet 🐧Git
: Essentials Cheatsheet 🌳- Further Resources 🔥
- Contribution & Collaboration 🤝
Git
is a distributed version control system (VCS
) that facilitates better coding efficiency and software maintenance. It is an essential tool for collaboration, allowing multiple people to work on the same project without conflicts. Here are some key points about Git
from these slides:
- Efficiency and Maintenance:
Git
optimizes the workflow in development projects, making it easier to track changes and maintain code. - Collaboration:
Git
is designed for team collaboration, enabling developers to work together on software projects seamlessly. - Versatility: It is not just for software development.
Git
is useful in any scenario that requires tracking changes, such as personal, university, and open-source projects. - Market Relevance: Many companies require knowledge of
Git
as part of their development process. - Popularity: Over 100 million developers use
GitHub
, a platform that integrates with Git, indicating the widespread adoption of this system. - Branch Management:
Git
allows the creation of multiple 'branches' which aid in isolated development efforts, thereby keeping the main project stable. - Version Control: It is crucial for managing complex projects.
Git
enables you to track iterations, revert to previous versions, and manage parallel work streams effectively.
Note
Git
should not be confused withGitHub
. WhileGit
is a version control system,GitHub
is a platform for hosting and sharing files and managingGit
repositories online. Other platforms likeGitLab
also useGit
. UnderstandingGit
is crucial for anyone involved in software development, and the number ofGit
users continues to grow exponentially.
Follow the steps below to setup Git
and GitHub
on your machine. Otherwise, you might also use the slides found here.
-
Check for Pre-installed Git:
- Open the terminal and type:
git --version
- If a version appears,
Git
is already installed on your machine.
- Open the terminal and type:
-
Install
Git
(if not already installed):- Download
Git
from this website. - Ensure to select the correct OS and the latest version.
- Download
- Sign Up:
- Go to github.com and follow the link to start a free account.
- Follows the steps, i.e. provide basic information (name, email, etc.).
- NB: Students can often get a
PRO account
free of charge.
- Set
Git
Credentials:- Open your terminal and set your Git credentials:
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
- Verify the setup by running:
git config --list
- Open your terminal and set your Git credentials:
- SSH Key Setup:
- Navigate to your SSH directory with:
cd ~/.ssh
- Check for existing SSH keys (don't worry if some commands look complicated):
(ls id_rsa && ls id_rsa.pub) && echo yes || echo no
- If you don’t have the SSH keys (
id_rsa
andid_rsa.pub
), generate them with:ssh-keygen -t rsa -C "your_email@example.com"
- Copy the SSH public key to your clipboard:
pbcopy < ~/.ssh/id_rsa.pub
- Go to github.com, click on
“Account Settings”
➡️“SSH Keys”
. - Add a label for your key (e.g.,
“My MacBook”
) and paste the copied key. - Confirm the setup by running:
ssh -T git@github.com
- You should see a message confirming that you've successfully authenticated.
- Navigate to your SSH directory with:
Note This guide covers the basic steps to install Git and set up GitHub on your machine. For more instructions, refer to the official Git Installation Guides.
Here are the top commands to get you started with navigating and managing files in a Linux Command Line
environment.
Command | Description |
---|---|
pwd |
Print the current working directory path. |
ls |
List all files and directories in the current directory. |
cd [directory] |
Change the current directory to the specified one. |
mkdir [directory] |
Create a new directory with the specified name. |
rmdir [directory] |
Remove a directory (must be empty). |
rm [file] |
Remove a specified file (for directory add -rf flag). |
cp [source] [destination] |
Copy files or directories from source to destination. |
mv [source] [destination] |
Move files or directories from source to destination. |
touch [file] |
Create a new file or update the timestamp of an existing file. |
echo [text] > [file] |
Write text to a file, overwriting previous content. |
cat [file] |
Display the contents of a file. |
chmod [permissions] [file] |
Change the file permission. |
grep [pattern] [file] |
Search for a pattern in a file and prints all matching lines. |
find [directory] -name [filename] |
Search for a file within a directory and its subdirectories. |
Furthermore, the table includes essential Git
commands (at least for me) and their brief descriptions.
Command | Description |
---|---|
git add [file] |
Add a file to the staging area, marking it for inclusion in the next commit. |
git branch [branch-name] |
Create a new branch with the specified name. |
git branch -a |
List all branches, including remote-tracking ones. |
git branch -r |
List all remote-tracking branches. |
git checkout [branch-name] |
Switch to the specified branch. |
git checkout -b [branch-name] |
Create a new branch and switch to it. |
git clone [repository] |
Clone a repository into a new directory. |
git commit -m "[message]" |
Record changes to the repository with the given commit message. |
git diff --patience |
Show differences between files with a more optimized algorithm. |
git diff --cached |
Show changes between the staging area and the last commit. |
git fetch [remote] |
Download objects and refs from another repository. |
git init |
Initialize a new Git repository. |
git log |
Show the commit logs. |
git pull [remote] [branch] |
Fetch from a remote repo and integrates with the current branch. |
git push [remote] [branch] |
Update remote refs along with associated objects. |
git push --force-with-lease |
Safely force-push changes ensuring you don't overwrite others' work (e.g. after rebasing). |
git rebase -i [branch] |
Reapply commits on top of another base tip interactively. |
git rebase --continue |
Continue the rebase after resolving conflicts. |
git rm -r --cached [file] |
Remove files from the index (staging area), but not from the working directory. |
git status |
Show the working tree status. |
git stash |
Stash the changes in a dirty working directory away. |
git stash pop |
Apply the stashed changes and remove them from the stash list. |
git switch -c [branch-name] |
Create a new branch and switch to it (newer version of checkout -b). |
Enhance your Git
and GitHub
experience with these advanced tools and concepts.
Create shortcuts for frequently used commands to streamline your Git
workflow. Here are some of my (many) suggestions. Feel free to add these aliases to your .zshrc
(or .bashrc
):
alias gadd='git add'
alias gbr='git branch'
alias gbr_all='git branch -a'
alias gcheck='git checkout'
alias gcheck_new='git checkout -b'
alias gclone='git clone'
alias gcomm='git commit -m'
alias gpull='git pull'
alias gpush='git push'
alias gst='git status'
The .gitignore
file is a must-have in any Git
repo. It tells Git
which files or directories to ignore in a particular project. Typically, you'll exclude: temporary files created by your IDE, build artifacts or compiled files, log files, databases, and config files with sensitive information.
Here is a simple .gitignore
example for Python
:
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# Distribution / packaging
.Python
build/
dist/
The GitHub CLI (gh
) extends GitHub
features to your terminal. Use it to manage repositories, issues, pull requests, and more without leaving your command line. It's a very efficient tool for developers who work predominantly within their terminals. Found out more here.
Note In case you found a mistake or had an idea on how to expand this guide, feel free to contact me via any of the links included in my GitHub bio page. You might also contribute to the project by opening a Pull Request with suggested improvements.