avatar_url

Sandesh Rana | Python

I'm a developer from Himalayas, with a passion for crafting efficient and elegant code, with creativity and precision.

Git Commands Cheatsheet

14 Feb 2022 » git

Git Command Cheatsheet

# When starting work on a new feature, branch off from the develop branch.
git checkout -b myfeature develop

# Finished features may be merged into the develop branch to definitely add them to the upcoming release:

git checkout develop
git merge --no-ff myfeature
git branch -d myfeature
git push origin develop

Commands

CommandDescription
git initInitializes a new Git repository in the current directory.
git clone <repository>Creates a local copy of a remote repository.
git statusShows the current status of the repository.
git add <file>Adds a file to the staging area for the next commit.
git commit -m "message"Records the changes in the repository with a descriptive message.
git diffShows the differences between the working directory and the staging area.
git logDisplays the commit history of the repository.
git branchLists all branches in the repository.
git checkout <branch>Switches to the specified branch.
git merge <branch>Combines changes from the specified branch into the current branch.
git pullFetches changes from a remote repository and merges them into the current branch.
git pushPushes the local commits to a remote repository.
git remote add <name> <url>Adds a new remote repository with the given name and URL.
git remote -vLists all remote repositories associated with the current repository.
git stashTemporarily saves changes that are not ready to be committed.
git reset <file>Removes a file from the staging area.
git revert <commit>Reverts the specified commit by creating a new commit.
git fetchDownloads changes from a remote repository without merging them.
git tagLists all tags in the repository.
git show <commit>Displays information about the specified commit.

Reference