- Introduction
- What is Git?
- Git vs GitHub
- Git Setup and Configuration
- Demo Repository Setup
- Staging Area Concept in Git
- Add and Commit [Local Repo]
- Git Collaboration
Welcome to the Git & GitHub Workshop! This workshop is designed to introduce you to the basics of Git and GitHub. Git is a version control system that allows you to track changes to your code and collaborate with others. GitHub is a web-based hosting service for version control using Git.
-
Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.
-
Git is a version control system that allows you to track changes to your code and collaborate with others.
Git | GitHub |
---|---|
Tool to control and track versions of code. | Cloud service to host git repositories. |
Installed and maintained locally on a developer's computer. | Remote connection provider and maintained on cloud/web. |
Generally uses command line interface (CLI) with a limited GUI. | Provides a graphical user interface (GUI) to interact with git repositories. |
Allows for branching and merging of code. | Offers pull requests and code review features for collaboration. |
Provides basic features like committing changes and creating branches. | Offers additional features like issue tracking, project management, and code hosting. |
-
Download and install Git from https://git-scm.com/downloads
-
Open Git Bash and check the version of Git installed:
git --version
- Configure Git with your name and email address:
git config --global user.name "Your Name"
git config --global user.email "Your Email"
-
Create a New Folder on your Desktop called
yourFolderName
: -
Open Git Bash and navigate to the folder you just created:
cd yourFolderName
- Initialize the folder as a Git repository:
git init
- If you didnot setup global configuration, you can configure Git with your name and email address:
git config user.name "Akib Zaman"
git config user.email "[email protected]"
You can also check the configuration:
git config --list
Check Global Email and Name:
git config user.email
git config user.name
- Create some files in the folder:
touch file1.txt
touch file2.txt
- Check the status of the repository:
git status
- Let’s add the new file to staging Area
-
Only a specific File:
git add <file_name>
-
Only files of a folder but not the subfolder:
git add .
orgit add *
-
All files and subfolders recursively:
git add -A
-
Only a particular type of file from directory:
git add *.c
-
Only a particular type of file from directory & subdirectory:
git add **/*.c
-
Only Commit:
git commit -m "Your Commit Message"
-
Commit and Add:
git commit -am "Your Commit Message"
-
Commit and Add with Editor:
git commit -a
-
See Commit History:
git log
or for a short version:git log --oneline
or for a short version with graph:git log --oneline --graph
-
See Commit History with Author:
git log --oneline --graph --all --decorate --author="Akib Zaman"
-
See Specific Commit:
git show <commit_id>
-
Local Repo to Staging Area:
git restore --staged <file_name>
-
Local Repo to Staging Area (Multiple Commit):
git reset --soft HEAD~<number_of_commit>
e.g.git reset --soft HEAD~2
-
Local Repo to Working Directory:
git restore <file_name>
-
Total Deletion of a Commit: `git reset --hard HEAD^
-
To a specific commit:
git checkout <commit_id>
-
To a specific branch:
git checkout <branch_name>
-
To a specific tag:
git checkout <tag_name>
-
Move back to the previous branch:
git checkout -
- Create a new branch:
git branch <branch_name>
- List all branches:
git branch
- Switch to a branch:
git checkout <branch_name>
- Create a new branch and switch to it:
git checkout -b <branch_name>
- Delete a branch:
git branch -d <branch_name>
- Merge a branch:
git merge <branch_name>
- Merge a branch with a commit message:
git merge <branch_name> -m "Your Commit Message"
-
Create a new repository on GitHub
-
Copy the remote repository URL
-
Add the remote repository URL to your local repository:
git remote add origin <remote_repository_URL>
-
Clone a Remote Repository:
git clone <remote_repository_URL>
-
Push to Remote Repository:
git push -u origin
-
Pull from Remote Repository:
git pull
-
Fetch from Remote Repository:
git fetch
-
Push setting the branch upstream:
git push --set-upstream origin <branch_name>