50 Git commands:

DevOps Enthusiast | Cloud & DevOps | Kubernetes | AWS | Ansible | GIT | Terraform | Gitlab | Docker | Python | Linux | Software Testing | Data Engineering
git initInitializes a new Git repository.$ git init Initialized empty Git repository in /path/to/repository/git cloneClones a remote repository to your local machine.$ git clone https://github.com/username/repository.git Cloning into 'repository'...git addStages changes for commit.$ git add file.txtgit statusShows the status of the working directory and staged changes.$ git statusgit commitCommits staged changes.$ git commit -m "Added new feature"git logDisplays commit history.$ git loggit diffShows differences between working directory and staged changes.$ git diffgit branchLists branches.$ git branchgit checkoutSwitches branches or restores files.$ git checkout branch_namegit mergeMerges changes from one branch into another.$ git merge feature_branchgit pullFetches and integrates changes from a remote repository.$ git pull origin mastergit pushPushes changes to a remote repository.$ git push origin mastergit remoteManages remote repositories.$ git remote add origin https://github.com/username/repository.gitgit fetchDownloads objects and refs from a remote repository.$ git fetch origingit stashTemporarily stores changes to work on something else.$ git stashgit tagCreates and manages tags for specific commits.$ git tag v1.0.0git resetUnstages changes or moves the HEAD to a specific commit.$ git reset HEAD file.txtgit rebaseReapplies commits on top of another base.$ git rebase mastergit configSets configuration options.$ git config --global user.name "Your Name" $ git config --global user.email "your.email@example.com"git log --onelineDisplays compact commit history.$ git log --onelinegit showShows information about a commit.$ git show commit_hashgit cherry-pickApplies a commit from one branch to another.$ git cherry-pick commit_hashgit rmRemoves files from the working directory and stages the removal.$ git rm file.txtgit revertCreates a new commit that undoes changes from a previous commit.$ git revert commit_hashgit reflogDisplays the history of HEAD positions.$ git refloggit cleanRemoves untracked files and directories from the working directory.$ git clean -n # Dry-run $ git clean -f # Force removalgit tag -aCreates an annotated tag with a message.$ git tag -a v1.0.0 -m "Version 1.0.0"git log --graphDisplays commit history as a graph.$ git log --graph --onelinegit config --listLists all Git configuration settings.$ git config --listgit log --since/git log --untilDisplays commit history within a time range.$ git log --since="2 weeks ago" $ git log --until="2023-07-01"git cherryShows commits that have not been merged.$ git cherry master feature_branchgit revert --no-commitReverts changes interactively without committing.$ git revert --no-commit commit_rangegit log --authorFilters commit history by author.$ git log --author="John Doe"git log --statDisplays file statistics with commit history.$ git log --statgit blameShows who last modified each line in a file.$ git blame file.txtgit tag -dDeletes a tag.$ git tag -d v1.0.0git log -pDisplays commit history with patch diffs.$ git log -pgit rev-parseConverts a revision string into a SHA-1 hash.$ git rev-parse HEADgit remote -vLists remote repositories and their URLs.$ git remote -vgit log --decorateDisplays references (branches, tags) in commit history.$ git log --decorategit bisectPerforms a binary search to find a faulty commit.$ git bisect start $ git bisect good <commit> $ git bisect bad <commit> $ git bisect resetgit log --grepSearches commit messages for a specific keyword.$ git log --grep="bug fix"git log --name-onlyDisplays only file names in commit history.$ git log --name-onlygit rebase -iInteractively rewrites commit history.$ git rebase -i HEAD~3git log --before/git log --afterDisplays commit history before/after a specific date.$ git log --before="2023-01-01" $ git log --after="2022-01-01"git checkout -bCreates a new branch and switches to it.$ git checkout -b new_featuregit log --cherry-pickShows commits that have been cherry-picked.$ git log --cherry-pick master..feature_branchgit log -SSearches for changes that added or removed a specific string.$ git log -S "function_name"git reflog expireExpires old reflog entries.$ git reflog expire --expire=30.days refs/heads/mastergit commit --amendModifies the most recent commit.$ git commit --amend




