Welcome to Git & GitHub for Beginners! This guide is designed to help you get started with Git & GitHub. It will help you to understand the basics of Git & GitHub and to get you started with using Git & GitHub.
- What is this?
- Why?
- Who is this for?
- Notes
- Assumptions
- Terms
- What is GitHub?
- What is GitHub used for?
- What is Git?
- Common tasks you need to do with Git
- How to install Git
- How to configure Git
- How to create a repository
- How to clone a repository
- How to create a branch
- How to make changes to a file
- How to stage changes
- How to commit changes
- How to push changes to a remote repository
- How to create a pull request
- How to merge a pull request
- How to resolve merge conflicts
- How to revert a commit
- How to delete a branch
- A guide to Git & GitHub for beginners
- A collection of resources to help you learn Git & GitHub
- A place to ask questions and get help
- I've been using Git & GitHub for a few years now and I've found it to be a really useful tool.- I've used it to collaborate with others on projects, to keep track of changes to my code, and to revert to previous versions of my code when I've made a mistake
- I've also found that there are a lot of resources out there that are either too basic or too advanced
- I wanted to create a guide that would help people who are new to Git & GitHub to get started and to help them to understand the basics of Git & GitHub
- Those who are yet to land their first job in tech
- Those who have recently landed their first job in tech
- Those who are looking to improve their skills
- Those who are looking to learn a new skill
- Those who are looking to get a better understanding of Git & GitHub
- There are different Git workflows - Trunk, GitFlow, GitHubFlow
- This guide is based on the GitHubFlow workflow
- You have a GitHub account
- You have Git installed
- You have a text editor installed
- You have Node.js installed
- Branch - A version of the codebase
- Commit - A unit of change
- Stage
- Merge - Combining two branches
- Pull Request - A request to merge a branch into another branch
- Fork - A copy of a repository
- Clone - A copy of a repository on your local machine
- Remote - A copy of a repository on a remote server
- Origin - The default remote name given to a repository when it is cloned
- Upstream - The original repository that was cloned
- Master - The default branch name given to a repository when it is created
- Repository - A directory that contains all of the files for a project
- Working Directory - The directory that contains the files that you are working on
- Staging Area - The directory that contains the files that are ready to be committed
- Index - The directory that contains the files that are ready to be committed
- HEAD - The current branch that you are working on
- Checkout - Switching between branches
- Push - Sending your commits to a remote repository
- Pull - Fetching and merging changes on a remote repository to your local repository
- Fetch - Fetching changes on a remote repository to your local repository
- GitHub is a code hosting platform for version control and collaboration
- It lets you and others work together on projects from anywhere
- This tutorial teaches you GitHub essentials like repositories, branches, commits, and Pull Requests
- You’ll create your own Hello World repository and learn GitHub’s Pull Request workflow, a popular way to create and review code
- You’ll also learn about issues, GitHub’s powerful tracking tools for every bug and feature request that comes your way
- GitHub is a code hosting platform for version control and collaboration
- It lets you and others work together on projects from anywhere
- You can use GitHub to store and share your code, track and assign issues, and manage pull requests
- You can also use GitHub to create your own website using GitHub Pages
- GitHub is a great way to collaborate with others on projects
-
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency
-
Git is easy to learn and has a tiny footprint with lightning fast performance
-
It outclasses SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and multiple workflows
-
Git was initially designed and developed by Linus Torvalds for Linux kernel development
-
Git is a version control system
-
Allows you to track changes to your code over time
-
Enables you to collaborate with others on the same codebase
-
You can easily revert to a previous version of your code or experiment with new features without affecting the main codebase
-
Provides a record of all changes made to your code, including who made them and when, which can be useful for auditing and debugging
- Create a repository
- Create a branch
- Make changes to a file
- Stage changes
- Commit changes
- Push changes to a remote repository
- Merge changes
- Revert changes
- Delete a branch
git config --global user.name "Your Name"
- Set a name that is identifiable for credit when review version history
# Set a name that is identifiable for credit when review version history
$ git config --global user.name "Your Name"
-
`git config --global user.email "
-
Set an email address that will be associated with each history marker
# Set an email address that will be associated with each history marker
$ git config --global user.email "
git config --global color.ui auto
- Set automatic command line coloring for Git for easy reviewing
# Set automatic command line coloring for Git for easy reviewing
$ git config --global color.ui auto
git config --global core.editor "code --wait"
- Set the default editor for Git
# Set the default editor for Git
$ git config --global core.editor "code --wait"
git config --global init.defaultBranch main
- Set the default branch name to main
# Set the default branch name to main
$ git config --global init.defaultBranch main
git init
- Create a new local repository
# Create a new directory called my-project
$ git init my-project
git status
- Show the status of the current branch
# Check the status of the current branch
$ git status # On branch master
git clone
- Clone a repository that already exists on GitHub to your local machine
#Clone a repository that already exists on GitHub to your local machine
$ git clone project-name # Cloning into `project-name`...
# make sure to copy the URL from the repository you want to clone
git add
- Add files to the staging area
# Add files to the staging area
$ git add . # Changes to be committed:
# when you add the dot, it adds all the files in the current directory
$ git add file-name # Changes to be committed:
# when you add the file name, it adds the file with the name you specified
git commit
- Commit changes to head (but not yet to the remote repository)
# Commit changes to head (but not yet to the remote repository)
$ git commit -m "Commit message" # [master (root-commit) 1a2b3c4] Commit message
git push
- Push changes to remote repository (eg. GitHub)
# Push changes to remote repository (eg. GitHub)
$ git push origin master # Pushing to
git pull
- Fetch and merge changes on the remote server to your working directory
# Fetch and merge changes on the remote server to your working directory
$ git pull origin master # Updating 1a2b3c4..3d4e5f6
# Fast-forward
# README | 1 +
# 1 file changed, 1 insertion(+)
# create mode 100644 README
git fetch
- Fetch changes on the remote server to your working directory
# Fetch changes on the remote server to your working directory
$ git fetch origin master # remote: Counting objects: 5, done.
git merge
- Merge a branch into the branch you are currently on
# Merge a branch into the branch you are currently on
$ git merge branch-name # Updating 1a2b3c4..3d4e5f6
- `git branch` - List, create, or delete branches
```bash
# List, create, or delete branches
$ git branch # * master
# test
$ git branch branch-name # * master
# branch-name
# test
$ git branch -d branch-name # Deleted branch branch-name (was 1a2b3c4).
git checkout
- Switch branches or restore working tree files
# Switch branches or restore working tree files
$ git checkout branch-name # Switched to branch 'branch-name'
$ git checkout -b branch-name # Switched to a new branch 'branch-name'
git remote
- Manage set of tracked repositories
# Manage set of tracked repositories
$ git remote -v # origin
git log
- Show commit logs
# Show commit logs
$ git log # commit 1a2b3c4
git diff
- Show changes between commits, commit and working tree, etc
# Show changes between commits, commit and working tree, etc
$ git diff # diff --git a/README.md b/README.md
git reset
- Reset current HEAD to the specified state
# Reset current HEAD to the specified state
$ git reset --hard HEAD # HEAD is now at 1a2b3c4
git rm
- Remove files from the working tree and from the index
# Remove files from the working tree and from the index
$ git rm file-name # rm 'file-name'
git mv
- Move or rename a file, a directory, or a symlink
# Move or rename a file, a directory, or a symlink
$ git mv file-from file-to # rename file1 => file2
git stash
- Stash the changes in a dirty working directory away
# Stash the changes in a dirty working directory away
$ git stash # Saved working directory and index state WIP on master: 1a2b3c4
git tag
- Create, list, delete or verify a tag object signed with GPG
# Create, list, delete or verify a tag object signed with GPG
$ git tag # v1.0.0
- Create a repository
- Create a branch
- Make changes to a file
- Stage changes
- Commit changes
- Push changes to a remote repository
- Merge changes
- Revert changes
- Delete a branch
git init
- Create a new local repository
# Create a new directory called my-project
$ git init my-project
git clone
- Clone a repository that already exists on GitHub to your local machine
# Clone a repository that already exists on GitHub to your local machine
$ git clone project-name # Cloning into `project-name`...
# make sure to copy the URL from the repository you want to clone
git status
- Show the status of the current branch
# Check the status of the current branch
$ git status # On branch master
git add
- Add files to the staging area
# Add files to the staging area
$ git add . # Changes to be committed:
# when you add the dot, it adds all the files in the current directory
$ git add file-name # Changes to be committed:
git commit
- Commit changes to the current branch
# Commit changes to the current branch
$ git commit -m "Commit message" # [master (root-commit) 1a2b3c4] Commit message
git diff
- Show file differences that haven’t been staged
# Show file differences that haven’t been staged
$ git diff # diff --git a/README.md b/README.md
git push
- Push changes to a remote repository
# Push changes to a remote repository
$ git push origin master # Enumerating objects: 3, done.
# Counting objects: 100% (3/3), done.
# Writing objects: 100% (3/3), 226 bytes | 226.00 KiB/s, done.
# Total 3 (delta 0), reused 0 (delta 0)
# To
git merge
- Merge changes from one branch to another
# Merge changes from one branch to another
$ git merge branch-name # Updating 1a2b3c4..4d5e6f7
git revert
- Revert changes to a file
# Revert changes to a file
$ git revert file-name # Revert "Revert "Update README.md""
git branch -d
- Delete a branch
# Delete a branch
$ git branch -d branch-name # Deleted branch branch-name (was 1a2b3c4).
git branch
- Create a new branch
# Create a new branch
$ git branch branch-name # Switched to a new branch 'branch-name'
git log
- View the history of a repository
# View the history of a repository
$ git log # commit 1a2b3c4 (HEAD -> master)