GitbashGitGudGIF
Git - The time machine of Developers 2

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.

Download

macOS

Install Git using Homebrew:

brew install git
Bash

Linux

Install Git using the package manager:

sudo apt-get install git        # Debian/Ubuntu
Bash
sudo yum install git            # Fedora
Bash

Getting Started with Git

Initializing a Repository

To create a new Git repository:

git init
Bash

Cloning a Repository

To clone an existing repository:

git clone <repository-url>
Bash

Basic Git Commands

Checking Status

To check the status of your working directory and staging area:

git status
Bash

Adding Files

To add files to the staging area:

git add <file-name>
Bash

To add all files:

git add .
Bash

Committing Changes

To commit changes with a message:

git commit -m "Your commit message"
Bash

Pushing Changes

To push changes to the remote repository:

git push origin <branch-name>
Bash

Pulling Changes

To pull changes from the remote repository:

git pull origin <branch-name>
Bash

Branching and Merging

Creating a Branch

To create a new branch:

git branch <branch-name>
Bash

Switching Branches

To switch to a different branch:

git checkout <branch-name>
Bash

Merging Branches

To merge a branch into the current branch:

git merge <branch-name>
Bash

Working with Remote Repositories

Adding a Remote

To add a remote repository:

git remote add origin <remote-url>
Bash

Fetching and Pulling

To fetch changes from the remote repository:

git fetch origin
Bash

To pull changes from the remote repository:

git pull origin <branch-name>
Bash

Pushing to Remote

To push changes to the remote repository:

git push origin <branch-name>
Bash

Advanced Git Commands

Stashing Changes

To stash changes:

git stash
Bash

To apply stashed changes:

git stash apply
Bash

Rebasing

To rebase your current branch onto another branch:

git rebase <branch-name>
Bash

To pick up, squash, or reset your commits :

git rebase HEAD~<No of Commits> -i
Bash
## force push
git push --force
Bash

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!

Categorized in: