This repository serves as a resource containing essential Git commands for quick reference.
Before using Git commands, make sure you have Git installed on your system. You can download it from Git's official website.
Set your username and email address for Git commits:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
View the current configuration:
git config --list
To create a new Git repository, navigate to your project directory and run:
git init
Clone an existing repository from a remote server (e.g., GitHub):
git clone <repository-url>
View the status of your files in the repository (modified, staged, untracked):
git status
Stage changes for the next commit:
git add <file-name>
To stage all changes, use:
git add .
Commit your staged changes with a message:
git commit -m "Your commit message"
To see the history of commits:
git log
Push your committed changes to a remote repository (e.g., GitHub):
git push origin main
Replace main with your branch name if different.
Fetch and merge changes from a remote repository:
git pull origin main
Create a new branch:
git branch <branch-name>
Switch to a different branch:
git checkout <branch-name>
Create and switch to a new branch simultaneously:
git checkout -b <branch-name>
Merge a branch into the current branch:
git merge <branch-name>
Temporarily save changes that are not ready to be committed:
git stash
To apply stashed changes:
git stash apply
List the remote repositories configured for your local repo:
git remote -v
To remove a file from your repository and stage the removal:
git rm <file-name>
Unstage changes (move them from staged to unstaged):
git reset <file-name>
To reset your entire working directory:
git reset --hard
These are some of the essential Git commands that you will use frequently. Understanding and mastering these commands will help you manage your codebase more efficiently.