Git Course Notes v1
Git Course Notes v1
This are the course notes for the Introduction to Git for GitLab course available on Skilshare.
Unit 1 - Introduction to Git
Lesson 1 - Welcome
💡 - Main ideas
Here is a quick overview of what we will learn:
Git basics
viewing the change history
creating and merging branches
working with remote repositories
creating merge requests
resolving conflicts
Lesson 2 - Prerequisites
💡 - Main ideas
you need to have Git installed on your computer
check if Git is installed by using this command: git --version
📚 - Resources
Git installation instructions
Setup Git for Windows 10
Setup Git for macOS
Setup Git for Linux
Lesson 3 - Creating a Git repository
💡 - Main ideas
a repository is a place that stores something
a Git repository stores files and keeps track of any changes
we want to be able to keep track of all changes, to see who has made them and, if needed, have
the possibility to revert to a previous version
to create a new Git repository run this command inside an empty folder:
mkdir my-cool-website
cd people
git init
git init has created a hidden folder called .git which stores the repository
use git status to check the current status of the repository
Lesson 4 - Configuring Git
💡 - Main ideas
to identify who has made a specific change, we need to configure our name and email
git config --global user.name "FIRST_NAME LAST_NAME"
git config --global user.email "[email protected]"
this will help anyone looking at the changes in the repository see who has made them
Lesson 5 - Your first Git commit
💡 - Main ideas
a commit is a snapshot of the repository at a point in time
steps to create a commit:
create a new file or modify an existing one
stage the file by running git add <FILE NAME>
commit the file by running git commit -m "Message"
Lesson 6 - Git staging explained
💡 - Main ideas
the staging process allows us to select which files we want to commit
to add all changes to a commit you can use git add . or git add --all
Lesson 7 - Unstaging changes
💡
💡 - Main ideas
if you wish to unstage a file, you can use the command:
git reset HEAD <FILE>
this works only for files that have not been committed already
Lesson 12 - Creating a branch
💡
💡 - Main ideas
branching helps you divert from the main development work
branches are often prefixed with feature , bugfix , hotfix etc.
create a new branch with: git checkout -b <BRANCH NAME>
to switch back to master/main run: git checkout master
Lesson 13 - Merging a branch (fast forward)
💡 - Main ideas
you have to be inside the branch where you want to have the result of the merge (typically the
master/main branch)
the command you use is git merge <BRANCH YOU WISH TO MERGE>
verify the command output says "fast-forward merge"
use git log to view the commits added
Lesson 14 - Merging a branch (recursive)
💡 - Main ideas
if you continue making changes in the master branch after the point in time the branch is created,
a fast-forward merge is no longer possible.
git merge will try to merge the branches even if they have different parents
Lesson 15 - Rebasing commits
💡 - Main ideas
we often try to avoid merge commits to keep the history clean
you run rebase on the branch you want to sync with the master/main branch
git rebase master