Master version control, collaboration, and advanced workflows with this in-depth Git & GitHub guide for all levels.
Git is a distributed version control system that helps you track changes in your code and collaborate with others. GitHub is a cloud-based hosting service for Git repositories, making it easy to share, review, and manage code with teams or the open source community.
brew install git
(with Homebrew)sudo apt install git
(Debian/Ubuntu)git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config --global core.editor "code --wait" # Use VSCode as editor
git init my-project
cd my-project
This creates a new folder my-project
with a Git repository.
git add filename
or git add .
git commit -m "Describe your changes"
git log
git clone https://github.com/username/repo.git
git status
Create a .gitignore
file to exclude files/folders from version control.
node_modules/
.env
*.log
Sign up at github.com.
git remote add origin https://github.com/username/repo.git
git push -u origin main # or master
git branch feature-x # Create branch
git checkout feature-x # Switch to branch
# or: git switch feature-x
git merge feature-x # Merge into current branch
git branch -d feature-x # Delete branch
git add conflicted-file
git commit
git stash # Save uncommitted changes
git stash pop # Restore them later
git reset HEAD filename
git checkout -- filename
git commit --amend
git remote -v # List remotes
git remote add upstream URL # Add another remote
git fetch upstream # Fetch changes
git merge upstream/main # Merge upstream changes
git checkout feature-x
git rebase main
Rebase rewrites commit history for a cleaner project history.
git rebase -i HEAD~5
Squash, edit, or reorder commits interactively.
git cherry-pick <commit-hash>
Apply a specific commit from another branch.
git tag v1.0.0
git push origin v1.0.0
Tags mark specific points in history (e.g., releases).
git submodule add https://github.com/other/repo.git path/to/submodule
git submodule update --init --recursive
Include other repositories inside your repo.
.github/workflows/ci.yml
git-crypt
or git-secret
for encrypting files.feat: add login page
git pull origin main
git log --oneline --graph --all
for a visual history.main
.git revert <commit>
to create a new commit that undoes changes, or git reset
for local history changes.git add
and git commit
.