Git Commands

Initializing a Repository

git init

Initialize a new Git repository.

Staging Changes

git add

Stage changes for the next commit.

Committing Changes

git commit -m "message"

Commit staged changes with a descriptive message.

Viewing Repository Status

git status

Check the status of files in the repository (staged, unstaged, etc).

Viewing Commit History

git log

View details of all commits.

git checkout <id> - Move to a specific commit temporarily.

git checkout main - Move back to the main branch.

Reverting Changes

git revert <id>

Create a new commit to revert changes made in a specific commit.

Exiting Vim Editor

Resetting Changes

git reset --hard <id>

Undo changes by deleting commits since <id> (caution: changes history).

Ignoring Files

.gitignore

Specify files and folders to ignore.

Branching

Creating and Managing Branches

Merging Branches

git merge <name> - Merge branches.

Deleting Branches

git branch -D <branchName> - Delete a branch.

Remote Repository Management

Connecting to a Remote

Pushing Changes

Pulling Changes

git pull - Pull changes from the remote repository.

Configuration

Setting User Information

Cloning a Repository

git clone <url>

Clone a remote repository to the local machine.

Collaboration and Workflow