Table of Contents
Practical tips for getting started with Git and GitHub
-
Learn your way around the GitHub documentation
You can waste a lot of time doing random searches on the internet. The best approach is to use the authorative guide.
-
Start with the Basics: Git Commands
Learn and practice the basic Git commands, such as
git init
,git add
,git commit
,git status
, andgit log
. These are the fundamental commands that you’ll use frequently.Set up a small project on your local machine and initialise a Git repository (
git init
). Make some changes, track them withgit add
, commit those changes, and check the status withgit status
and the commit history withgit log
. -
Use GitHub for Remote Repositories
Create a GitHub account and use it to host your repositories remotely. Understand the difference between local and remote repositories and how to interact with them.
Create a repository on GitHub, clone it to your local machine using
git clone
, and start making changes. Push updates to the remote repository usinggit push
and pull changes from the remote repository withgit pull
. -
Understand the Purpose of
.gitignore
Learn how to use the
.gitignore
file to exclude files that don’t belong in version control, such as logs, build artifacts, and sensitive data like API keys.Create a
.gitignore
file in your project and add entries like*.log
,node_modules/
, or.env
to prevent Git from tracking those files. Commit the.gitignore
file to your repository. -
Work with Cloning and Forking
Understand how cloning and forking work in GitHub. Cloning creates a local copy of a repository, while forking makes a personal copy of someone else’s repository that you can modify.
Practice cloning a repository from GitHub using
git clone
. If you’re interested in contributing to an open-source project, fork the repository and clone your fork. Then, make changes and submit a pull request to the original project. -
Practice Working with Remote Repositories
Understand how to synchronise local and remote repositories using
git push
andgit pull
. These commands allow you to send your changes to GitHub and retrieve updates from the remote repository.Make changes to your local repository, commit them, and push them to GitHub. Ask a collaborator to make changes, and practice pulling their updates to your local environment.
-
Experiment with
.gitignore
TemplatesUse
.gitignore
templates for different programming languages or environments. GitHub offers a variety of templates that you can use as a starting point.Search for a
.gitignore
template for your project type (e.g., Python, Node.js) on GitHub’s.gitignore
repository and use it in your project. Customise the template as needed. -
Understand the Difference Between
git pull
andgit fetch
git pull
retrieves and merges changes from the remote repository, whilegit fetch
only downloads changes without merging. Knowing when to use each can help you avoid unwanted merges.Practice using both commands. Try
git fetch
to see what changes are available on the remote without affecting your working directory, and then manually merge changes withgit merge
if needed. -
Experiment with Undoing Changes
Learn how to undo changes safely using
git reset
,git revert
, andgit checkout
. These commands help you undo commits or changes to the working directory.Make intentional mistakes or commits and practice undoing them using different methods. For example, use
git reset
to unstage files,git checkout
to revert changes to a file, andgit revert
to undo a commit while keeping the history intact. -
Keep Track of Changes with
git diff
Use
git diff
to see the differences between your working directory, staging area, and the latest commit. This helps you review changes before committing.Before committing, run
git diff
to review the changes you’ve made. Then usegit add
to stage the changes and commit them withgit commit
.