0% found this document useful (0 votes)
0 views

Git_Commands_Guide

This document is a comprehensive guide to Git commands covering setup, repository management, branching and merging, working with remote repositories, undoing changes, and additional commands. It includes instructions for installing Git, configuring user details, managing branches, and handling commits and remote repositories. Each section provides specific commands and their purposes for effective version control using Git.

Uploaded by

mowesis739
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Git_Commands_Guide

This document is a comprehensive guide to Git commands covering setup, repository management, branching and merging, working with remote repositories, undoing changes, and additional commands. It includes instructions for installing Git, configuring user details, managing branches, and handling commits and remote repositories. Each section provides specific commands and their purposes for effective version control using Git.

Uploaded by

mowesis739
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Git Commands Guide

1. Git Setup

- Install Git:
Download from https://git-scm.com/ and install.
- Check Git Version:
git --version
- Set User Name:
git config --global user.name "Your Name"
- Set User Email:
git config --global user.email "[email protected]"
- View Configurations:
git config --list

2. Repository Management

- Initialize a Repository:
git init
- Check Repository Status:
git status
- Add Files to Staging:
git add . # Adds all files
- Commit Changes:
git commit -m "Your commit message"
- View Commit History:
git log

3. Branching & Merging

- Create a New Branch:


git branch branch-name
- Switch to a Branch:
git checkout branch-name
- Create and Switch to Branch:
git checkout -b branch-name
- Merge a Branch:
git merge branch-name
- Delete a Branch:
git branch -d branch-name

4. Working with Remote Repositories

- Add Remote Repository:


git remote add origin https://github.com/user/repo.git
- View Remote URLs:
git remote -v
- Push to Remote:
git push origin branch-name
- Pull Latest Changes:
git pull origin branch-name
- Clone a Repository:
git clone https://github.com/user/repo.git

5. Undoing Changes

- Undo Last Commit:


git reset --soft HEAD~1 # Keeps changes
- Undo Last Commit Completely:
git reset --hard HEAD~1 # Removes changes
- Discard Unstaged Changes:
git checkout -- file-name
- Remove File from Staging:
git reset file-name

6. Additional Commands

- Create .gitignore File:


touch .gitignore # Add ignored files inside it
- Show File Differences:
git diff
- Show Last Commit Changes:
git show
- Stash Uncommitted Changes:
git stash
- Apply Stashed Changes:
git stash pop

You might also like