Skip to content

A comprehensive guide to essential Git commands with explanations. Perfect for beginners and advanced users to manage version control efficiently. πŸš€

Notifications You must be signed in to change notification settings

Owaisi123/git-commands-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Git Commands Guide

This repository contains essential Git commands with explanations to help developers efficiently manage their projects using Git.

Getting Started with Git

1. Check Git Version

git --version

Checks the installed Git version.

2. Initialize a New Repository

git init

Creates a new Git repository in the current directory.

3. Configure Git User

git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"

Sets your global Git username and email.

4. View Git Configuration

git config --list

Lists all configured Git settings.

Working with Changes

5. Check Repository Status

git status

Shows the current state of the repository, including untracked and modified files.

6. Add Files to Staging

git add <file1> <file2>

Adds specific files to the staging area.

git add .

Adds all changes to the staging area.

7. Commit Changes

git commit -m "Your commit message"

Creates a new commit with the staged changes.

Viewing History

8. View Commit History

git log

Displays a list of previous commits with details.

git log --oneline

Shows commit history in a compact format.

Branching and Merging

9. List Branches

git branch

Shows all local branches.

10. Create a New Branch

git branch <branch-name>

Creates a new branch without switching to it.

11. Switch to a Branch

git switch <branch-name>

Switches to an existing branch.

12. Create and Switch to a New Branch

git switch -c <branch-name>

Creates a new branch and switches to it.

13. Merge a Branch

git merge <branch-name>

Merges the specified branch into the current branch.

14. Rebase a Branch

git rebase <branch-name>

Reapplies commits from the current branch onto the specified branch.

15. Cherry-Pick a Commit

git cherry-pick <commit-id>

Applies a specific commit from another branch.

16. Rename a Branch

git branch -m <old-branch-name> <new-branch-name>

Renames an existing branch.

17. Delete a Branch

git branch -d <branch-name>

Deletes a branch if it is merged.

git branch -D <branch-name>

Force deletes a branch, even if it is not merged.

Uploading to GitHub

18. Connect to a Remote Repository

git remote add origin <repository-url>

Links the local repository to a GitHub repository.

19. Push Changes to GitHub

git push -u origin main

Uploads the local commits to the GitHub repository.

20. Pull Latest Changes from GitHub

git pull origin main

Fetches and merges the latest changes from the remote repository.

Conclusion

This guide covers fundamental Git commands for efficient version control. Keep practicing and exploring Git to improve your workflow!

About

A comprehensive guide to essential Git commands with explanations. Perfect for beginners and advanced users to manage version control efficiently. πŸš€

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published