GIT Commands

2 minutes read

Git Commands List


sudo apt install git – installs GIT from repositories;


git config –global “Your Name” – the name that will be added to commits and tags;
git config –global “” – the e-mail address that will be added to commits and tags;
git config –global color.ui auto – enables the colors in GIT output;


git init [project name] – creates a new local repository;
git clone [project url] – gets a project from remote repository;


git status – shows the status of your work;
git diff – shows the changes;
git checkout – discards changes in working directory;
git add – adds a file to staging area;
git reset [file] – gets file back from staging area;
git commit [-m “message”] – commits the changes added to staging area;
git rm [file] – removed the file from working directory and adds deletion to staging area;
git stash – puts changes into stash;
git stash pop – applies the changes in the stash and clears its contents;
git stash drop – clears the stash contents;


git branch [-a] – lists all branches in repository;
git branch [name] – creates a new branch;
git checkout [-b] [name] – changes working directory to the mentioned one;
git merge [from name] – Combines the specified branch with the current one;
git branch -d [name] – removes branch;


git tag – lists tags;
git tag [name] [commit *] – creates a tag for current commit;
git tag -a [name] [commit *] – creates a tag object for current commit;
git tag -d [name] – removes a tag from repository;


git log [-n count] – lists commit history;
git log –oneline –graph –decorate – shows references and history graph;
git log ref.. – shows commits that are present on current branch and not merged into ref;
git log ..ref – lists commits that are present on ref and not merged into current branch;
git reflog – list operations made on local repository;


git fetch [remote] – gets changes from the remote but does not update the branches;
git fetch –prune [remote] – removes refs from remote;
git pull [remote] – gets changes from the remote and combines current branch with it;
git push [–tags] [remote] – pushes local changes to remote;
git push -u [remote] [branch] – pushes local branch to remote repository;


git reset [–hard] [target reference] – switches current branch to the target reference;
git revert [commit *] – createa a new commit, reverting changes from the specified commit;


cat .gitignore
#Contents of .gitignore

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

Related Posts:

To initialize a Git repository in a new project, follow these steps:Open your project directory in a terminal or command prompt.Initialize a new Git repository by running the command: git init.This will create a hidden .git directory, which contains all the ne...
Creating and applying Git tags is a useful way to label specific points in a Git repository's history. Tags can be used to mark significant versions or milestones in a project. Here's how you can create and apply Git tags:Creating a Git tag: To create ...
Git hooks are scripts that can be executed automatically whenever certain actions occur in a Git repository. By using Git hooks, you can automate various tasks and enforce certain workflows in your development process.To use Git hooks for automation, follow th...
To clone a subset of Git branches, you can follow these steps:Open a terminal or Git bash.Navigate to the directory where you want to clone the repository.Clone the repository using the git clone command followed by the repository URL: git clone <repository...
To delete the merge history of a file in Git, you can follow these steps:Open a terminal or Git Bash and navigate to the directory of your Git repository. Use the git log --follow command to view the complete history of the file, including merge commits. Make...
To commit changes to a Git repository, you need to follow these steps:Add files to the staging area: Use the command git add to add specific files or git add . to add all modified files to the staging area. This prepares them for the commit. Check the status:...