Welcome to the Git Workshop! This workshop is designed to introduce you to Git, a distributed version control system that helps manage and track changes in your code.
Introduction to Git
Git is a distributed version control system created by Linus Torvalds in 2005. It allows multiple developers to work on a project simultaneously, track changes, and collaborate effectively. Git is widely used in the software development industry and is a fundamental tool for version control.
Installation
Windows
Download the Git installer from the official Git website and follow the installation instructions.
macOS
Install Git using Homebrew:
brew install git
Linux
Install Git using the package manager:
sudo apt-get install git # Debian/Ubuntu
sudo yum install git # Fedora
Getting Started with Git
Initializing a Repository
To create a new Git repository:
git init
Cloning a Repository
To clone an existing repository:
git clone <repository-url>
Basic Git Commands
Checking Status
To check the status of your working directory and staging area:
git status
Adding Files
To add files to the staging area:
git add <file-name>
To add all files:
git add .
Committing Changes
To commit changes with a message:
git commit -m "Your commit message"
Pushing Changes
To push changes to the remote repository:
git push origin <branch-name>
Pulling Changes
To pull changes from the remote repository:
git pull origin <branch-name>
Branching and Merging
Creating a Branch
To create a new branch:
git branch <branch-name>
Switching Branches
To switch to a different branch:
git checkout <branch-name>
Merging Branches
To merge a branch into the current branch:
git merge <branch-name>
Working with Remote Repositories
Adding a Remote
To add a remote repository:
git remote add origin <remote-url>
Fetching and Pulling
To fetch changes from the remote repository:
git fetch origin
To pull changes from the remote repository:
git pull origin <branch-name>
Pushing to Remote
To push changes to the remote repository:
git push origin <branch-name>
Advanced Git Commands
Stashing Changes
To stash changes:
git stash
To apply stashed changes:
git stash apply
Rebasing
To rebase your current branch onto another branch:
git rebase <branch-name>
To pick up, squash, or reset your commits :
git rebase HEAD~<No of Commits> -i
## force push
git push --force
Best Practices
- Commit often with meaningful messages.
- Use branches for new features or bug fixes.
- Keep your branch history clean by rebasing and squashing commits.
- Regularly push your changes to remote repositories.
- Review code and collaborate using pull requests.
Resources
Q&A
Feel free to ask any questions during the workshop. Happy coding!