Skip to content

This GitHub repository serves as a comprehensive guide to essential Git commands.

Notifications You must be signed in to change notification settings

Raajesh3108/Git-Commands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Git-Commands

Table of Contents

Git Repository

Git Initialization:

git init

Delet the Initialized git repository:

This will remove the version control system

rm -rf .git

Display the status of git repository:

git status

Display commits history:

git log

Basics

Add all files to staging area:

git add .

Remove all files from staging area:

git rm --cached -r .

Commiting the staging area files:

git commit -m "Intial Commit"

Remote Repository

Pushing Local Repository to Remote:

git push origin master

Pull from Remote to Local:

git pull

Cloning a Remote Repository:

git clone <url>

Merging a Remote Branch with Local:

git pull origin <branch_name>

This command merges the remote branch with the local repository.

Branches

Creating a branch:

git branch <branch-name>

Displaying all the branches:

git branch

Merging a Branch with the Main Branch:

git merge <branch-name>

Git Checkout

Switching Branches:

git checkout <branch-name>

Create a new branch and switch to it:

git checkout -b feature/new-feature

Check out a specific commit:

git checkout <commit-hash>

Go to the latest commit of the working branch:

git checkout <branch-name>

This updates your working directory to the latest commit on the specified branch.

Reversing Changes

Reset to a specific commit:

git reset [options] <commit-hash>

This resets the state of your repository to the specified commit.

Reset Soft (keep changes in staging):

git reset --soft <commit-hash>

This undoes the last commit but keeps the changes from that commit in the working directory and staging area.

Reset Hard (Discard Changes):

git reset --hard <commit-hash>

This permanently moves the branch pointer to the specified commit, resets the staging area, and discards all changes in your working directory.

Note: After resetting, you may want to update the remote repository:

git push --force origin <branch-name>

Git Clean

Check for Untracked Files:

git clean -n

Remove Untracked Files:

git clean -f

Use this with caution, as it permanently deletes untracked files.

Git Revert

Revert a Specific Commit:

git revert <commit-hash>

This creates a new commit that undoes the changes made by a previous commit.

Git Subtree

Git subtree allows you to embed one Git repository within another as a subdirectory.

Add a Subtree:

git subtree add --prefix=subdir-name remote-repo.git branch-name

Summary

Summary

About

This GitHub repository serves as a comprehensive guide to essential Git commands.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published