Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Pratik Pathak
Pratik Pathak

Posted on • Originally published atpratikpathak.com on

Git – The time machine of Developers

GitbashGitGudGIF

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 theofficial Git website and follow the installation instructions.

Download

macOS

Install Git using Homebrew:

brew install git
Enter fullscreen modeExit fullscreen mode

Linux

Install Git using the package manager:

sudo apt-get install git # Debian/Ubuntusudo yum install git # Fedora
Enter fullscreen modeExit fullscreen mode

Getting Started with Git

Initializing a Repository

To create a new Git repository:

git init
Enter fullscreen modeExit fullscreen mode

Cloning a Repository

To clone an existing repository:

git clone <repository-url>
Enter fullscreen modeExit fullscreen mode

Basic Git Commands

Checking Status

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

git status
Enter fullscreen modeExit fullscreen mode

Adding Files

To add files to the staging area:

git add <file-name>
Enter fullscreen modeExit fullscreen mode

To add all files:

git add .
Enter fullscreen modeExit fullscreen mode

Committing Changes

To commit changes with a message:

git commit -m "Your commit message"
Enter fullscreen modeExit fullscreen mode

Pushing Changes

To push changes to the remote repository:

git push origin <branch-name>
Enter fullscreen modeExit fullscreen mode

Pulling Changes

To pull changes from the remote repository:

git pull origin <branch-name>
Enter fullscreen modeExit fullscreen mode

Branching and Merging

Creating a Branch

To create a new branch:

git branch <branch-name>
Enter fullscreen modeExit fullscreen mode

Switching Branches

To switch to a different branch:

git checkout <branch-name>
Enter fullscreen modeExit fullscreen mode

Merging Branches

To merge a branch into the current branch:

git merge <branch-name>
Enter fullscreen modeExit fullscreen mode

Working with Remote Repositories

Adding a Remote

To add a remote repository:

git remote add origin <remote-url>
Enter fullscreen modeExit fullscreen mode

Fetching and Pulling

To fetch changes from the remote repository:

git fetch origin
Enter fullscreen modeExit fullscreen mode

To pull changes from the remote repository:

git pull origin <branch-name>
Enter fullscreen modeExit fullscreen mode

Pushing to Remote

To push changes to the remote repository:

git push origin <branch-name>
Enter fullscreen modeExit fullscreen mode

Advanced Git Commands

Stashing Changes

To stash changes:

git stash
Enter fullscreen modeExit fullscreen mode

To apply stashed changes:

git stash apply
Enter fullscreen modeExit fullscreen mode

Rebasing

To rebase your current branch onto another branch:

git rebase <branch-name>
Enter fullscreen modeExit fullscreen mode

To pick up, squash, or reset your commits :

git rebase HEAD~<No of Commits> -i## force pushgit push --force
Enter fullscreen modeExit fullscreen mode

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!

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Pratik Pathak is a highly accomplished technology professional with a passion for sharing his knowledge and expertise with others. As a Microsoft Certified Trainer, Pratik is dedicated to helping indi
  • Location
    Mumbai, India
  • Joined

More fromPratik Pathak

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp