Skip to content

Latest commit

 

History

History
72 lines (43 loc) · 1.99 KB

Commands.md

File metadata and controls

72 lines (43 loc) · 1.99 KB

Git Commands Reference

This file serves as a quick reference for commonly used Git commands.

Configuring Git

  • git config --global user.name "Your Name"
    Sets the name you want attached to your commits. Use --global to set this for all repositories.

  • git config --global user.email "your.email@example.com"
    Sets the email you want attached to your commits. Use --global to set this for all repositories.

  • git config --list
    Lists all Git configurations currently set on your system.

Initializing a Repository

  • git init
    Initializes a new Git repository in the current directory.

Staging and Committing Changes

  • git add <file>
    Stages a specific file (or files) for commit.

  • git commit -m "message"
    Commits staged changes with a message describing the commit.

Pushing Changes

  • git push
    Pushes local commits to a remote repository.

Checking Status and Differences

  • git diff
    Shows differences between the working directory and the staging area.

  • git status
    Displays the status of the working directory and the staging area.

  • git log
    Shows the commit history.

Undoing Changes

  • git reset --hard <commit ID>
    Resets the repository to the specified commit, discarding all changes after that commit.

Working with Branches

  • git checkout -b <branch name>
    Creates and switches to a new branch with the specified name.

Merging Changes

There are three main commands for merging changes between branches:

  • git cherry-pick <commit ID>
    Adds specific commits from one branch to another (often used to apply single commits to main).

  • git merge <branch name>
    Merges changes from the specified branch into the current branch without reordering commits.

  • git rebase <branch name>
    Merges changes from the specified branch into the current branch with a linear commit history.


Use these commands to manage your Git workflow effectively!