git --versionDisplays the installed Git version.
git config --global user.name "FIRST_NAME LAST_NAME"
git config --global user.email "MY_NAME@example.com"Sets your global username and email for commits.
git initCreates a new Git repository.
rm -rf .gitRemoves the Git repository from the project.
git statusShows the current status of files in the repository.
git logDisplays the commit history.
git clone URL.gitClones a repository from a remote URL.
git add .
git add somefile.javaStages all files or a specific file for commit. Show or add modifed files only:
git ls-files -m
git ls-files -m | xargs git addgit rm --cached <file>
git rm -r --cached <directory>Untracks a file or directory without deleting it.
git commit -m 'initial commit'Commits staged changes with a message.
git checkout -b devCreates and switches to a new branch named "dev".
git branch -d devDeletes the "dev" branch.
git checkout masterSwitches to the master branch.
git merge otherbranchMerges changes from "otherbranch" into the current branch.
git remote add origin "URL.git"Adds a remote repository with the alias "origin".
git remote -vLists all remote repositories.
git push -uf origin masterPushes changes to the remote repository, forcing updates.
git pull origin masterFetches and merges changes from the remote master branch.
git fetch origin
git reset --mixed origin/masterResets the current branch to match the remote master.
Resets everything to the specified commit, discarding all local changes.
Resets the index but keeps local changes intact.
Keeps the index and working directory unchanged; changes are staged for commit.
Resets the index and affected files from a failed merge, keeping other changes.
To prevent issues with file permissions across platforms:
git config core.fileMode false
git config --global core.fileMode falseDisables tracking of file mode changes in Git.
git stash listDisplays a list of all stashed changes.
git stash show [<stash>]Shows a summary of changes in the specified stash. If no stash is specified, it shows the latest stash.
git stash drop [<stash>]Removes the specified stash from the stash list. If no stash is specified, it drops the latest stash.
git stash pop [<stash>]Applies the changes from the specified stash and removes it from the stash list. If no stash is specified, it pops the latest stash.
git stash apply [<stash>]Applies the changes from the specified stash without removing it from the stash list. If no stash is specified, it applies the latest stash.
git stash branch <branchname> [<stash>]Creates a new branch from the specified stash and applies the changes. If no stash is specified, it uses the latest stash.
git stashStashes the current changes in the working directory and index.
git stash save "message"Stashes the current changes with an optional message for identification.
git stash clearRemoves all stashed changes from the stash list.
git stash create [<message>]Creates a stash without applying it to the working directory. Optionally, you can provide a message.
git stash store [-m <message>] <stash>Stores a stash with an optional message. You can specify which stash to store.
Sure! Here are the Git Worktree commands with detailed explanations:
git worktree add [-f] [--detach] [--checkout] [--lock [--reason <string>]] [--orphan] [(-b | -B) <new-branch>] <path> [<commit-ish>]Creates a new worktree at the specified path for the given branch or commit. Options include:
-f: Force the addition of the worktree.--detach: Create a detached HEAD worktree.--checkout: Checkout the specified commit or branch.--lock [--reason <string>]: Lock the worktree to prevent changes, with an optional reason.--orphan: Create an orphan branch.-b <new-branch>: Create a new branch and switch to it.-B <new-branch>: Create or reset a branch to the specified commit.
git worktree list [-v | --porcelain [-z]]Displays all active worktrees associated with the repository. Options include:
-v: Verbose output.--porcelain: Machine-readable output.-z: Use null character as delimiter for paths.
git worktree lock [--reason <string>] <worktree>Locks the specified worktree to prevent changes. Optionally, provide a reason for locking.
git worktree move <worktree> <new-path>Moves the specified worktree to a new path.
git worktree prune [-n] [-v] [--expire <expire>]Removes references to worktrees that no longer exist. Options include:
-n: Dry run, show what would be pruned without actually doing it.-v: Verbose output.--expire <expire>: Specify an expiration time for pruning.
git worktree remove [-f] <worktree>Removes the specified worktree. Use -f to force removal if there are uncommitted changes.
git worktree repair [<path>…]Repairs the specified worktree(s) if they are in a broken state.
git worktree unlock <worktree>Unlocks the specified worktree, allowing changes to be made again.