Notes|A List of Basic Git Commands
A list of essential Git commands that are commonly used for version control and collaboration:
Basic Git Commands
Initialize a repository:
git init- Creates a new Git repository in your project directory.
Clone a repository:
git clone [repository URL]- Copies an existing repository to your local machine.
Check the status:
git status- Shows the status of your working directory and staging area (e.g., changes, staged files).
Add files to staging:
git add [file]- Stages a specific file.
git add .- Stages all changes in the current directory.
Commit changes:
git commit -m "[message]"- Records staged changes with a commit message.
View commit history:
git log- Displays the commit history.
Branching:
git branch- Lists branches in the repository.
git branch [branch_name]- Creates a new branch.
Switch branches:
git checkout [branch_name]- Switches to the specified branch.
git switch [branch_name](modern alternative)- Switches branches.
Merge branches:
git merge [branch_name]- Merges the specified branch into the current branch.
Push changes to a remote repository:
git push [remote] [branch]- Pushes changes to a specific branch in the remote repository.
Pull changes from a remote repository:
git pull- Fetches and integrates changes from the remote repository into the current branch.
Discard changes:
git checkout -- [file]- Discards changes in the working directory (reverts to the last committed state).
git reset --hard- Resets the staging area and working directory to the last commit.
Stash changes:
git stash- Temporarily stores changes not ready to commit.
git stash apply- Restores the stashed changes.
View differences:
git diff- Shows differences between changes in the working directory and the staged area.
Remove files:
git rm [file]- Removes a file from the working directory and stages its deletion.
Tagging:
git tag [tag_name]- Creates a tag for a specific commit.