Git & friends
Available at lcgodoy.me/slides/2025-git/
2025-02-03
Does anyone relate to this?
Why is this useful?
Collaboration: Multiple people can work on the same project without overwriting each other’s changes.
Reverting: You can easily go back to a previous version if you make a mistake or want to try something different.
Tracking History: You can see who made what changes and when.
Git is a distributed version control system. This means that everyone working on a project has a complete copy of the project’s history on their own computer.
It was created by Linus Torvalds (the creator of Linux) in 2005 because he needed a better way to manage the Linux kernel source code.
The distributed nature of Git is a key benefit. If one person’s computer crashes, the project history is safe because everyone else has a copy.
This is important: Git and GitHub are not the same thing.
Git: The tool itself. It’s the software you install on your computer to track changes to your files.
GitHub: A website that hosts Git repositories. It’s a platform built around Git. Think of it like a place to store and share your Git projects.
GitHub is very popular, but it’s not the only option. Other platforms include:
terminal
Git’s Best Friend: Git relies heavily on the command line (terminal).
Power and Flexibility: The terminal offers direct control over your computer, enabling complex tasks and automation not easily achievable through graphical interfaces.
High-Performance Computing: A must-have for HPC.
Not as Scary as it Looks: The terminal is simply a text-based way to communicate with your computer. It’s a skill worth learning!
pwd
(print working directory): Tells you where you are in the file system.
ls
(list files): Shows you the files and folders in your current directory.
cd
(change directory): Moves you to a different folder. For instance, cd ..
goes up one level.
mkdir
(make directory): Creates a new folder.
touch
(create a file): Creates an empty file (often used for quick testing).
A repository (often shortened to repo) is a directory/folder plus a hidden .git
folder, which stores all the version history.
There are different ways to start a Git repository.
We can create or turn an existing directory/folder into a Git repository.
To turn a folder into a git repository, open your terminal, navigate to the desired folder (using cd
) and then type:
We can clone
a git repository.
If we replace <file>
by .
, then everything that was changed will be staged.
To see what’s been staged, use:
The -m
flag lets you pair the staged changes with a message describing the changes you made.
Good commit messages are essential! They help you and others understand the history of the project.
To see the history of commits (the commit messages, author, and date of each commit), use:
.gitignore
fileThe .gitignore
file is text file that tells Git which files and directories to ignore. This prevents them from being accidentally added to your repository and keeps your commit history clean.
Exclude unnecessary files: Avoid committing temporary files, log files, or system-specific files that clutter your repository.
Protect sensitive data: Prevent accidentally committing passwords, API keys, or other confidential information.
Example .gitignore
:
.DS_Store # macOS file
*.tmp # Temporary files
config.ini # Sensitive configuration
my_secret_key # Never commit secrets!
Pushing: Uploading your changes to a remote repository (like on GitHub). After a commit, to upload our changes to the remote repository, we run:
Pulling: Downloading changes from a remote repository to your local computer.
Best practice: Run git pull
before starting to edit a file to avoid conflicts.
Branches
Pull requests
Merging
Version control helps you track changes to your files.
Git is a powerful, distributed version control system.
GitHub is a platform for hosting Git repositories.
Basic commands: init
, add
, commit
, log
, clone
.
Git practice: more advanced exercises
Experiment with Git! Create a simple project and try out the basic commands.
Practice is key! The more you use Git, the more comfortable you’ll become.