Here is a detailed list of useful Git commands, along with illustrative examples:
git init
Initialize a new Git repository in your project directory.
Example:
git clone [url]
Clone a remote repository from the server to your local machine.
Example:
git add [file]
Add one or more files to the staging area to prepare for a commit.
Example:
git commit -m "message"
Create a new commit with the changes that have been added to the staging area and include your commit message.
Example:
git status
View the current status of the repository, including modified files and the staging area.
Example:
git log
Display the commit history of the repository.
Example:
git branch
List all branches in the repository and mark the current branch.
Example:
git checkout [branch]
Switch to another branch in the repository.
Example:
git merge [branch]
Merge another branch into the current branch.
Example:
git pull
Fetch and integrate changes from a remote repository into the current branch.
Example:
git push
Push changes from the current branch to a remote repository.
Example:
git remote add [name] [url]
Add a new remote server to your list of remote repositories.
Example:
git fetch
Download changes from remote repositories but don't integrate into the current branch.
Example:
git diff
Compare changes between the staging area and the tracked files.
Example:
git reset [file]
Remove a file from the staging area and revert it to the previous state.
Example:
git stash
emporarily save uncommitted changes to work on a different branch without committing them.
Example:
git remote -v
List the remote servers and their url addresses.
Example: