Git commands

touch text.txt – creates a file named text.txt

npp text.txt – opens a file named text.txt in Notepad++ (Notepad++ should be installed and set up to work with Git Bash). To get back to Git Bash, you should close Notepad++.

rm -rf folder – deletes a folder named folder. Be very careful. It will delete all folders and files within this current folder.

rm text.txt – deletes a file, that is untracked by git.

git rm text.txt – deletes a file, that is already tracked by git.

mv order.txt orderNew.txt – renames file or folder. Then type git add -A, which recursively add any changes (renamed or deleted).

You can also type git mv file1 file2. Then git commit -m “renaming file1 file”

git mv level2.txt level3 – moves a file to another folder.

git mv level2.txt .. – moves a file to one directory up.

git init – creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository. Most other Git commands are not available outside of an initialized repository, so this is usually the first command you’ll run in a new project.

git clone – cloning repository from

clear – clears the command line

git ls-files – shows a list of all files the GIT is tracking in the current repository.

git restore text.txt – to discard changes in the working directory (when modified message is red)

git restore –staged text.txt – to unstage (message turns green to red).

git add -u – correctly sees updating of a file.

git checkout – discards whatever changes that were made to the working directory

git log – shows commit history. To exit to console – type “q”.

git log –abbrev-commit – makes commit id shorter.

git log –oneline –graph –decorate – the same in a shorter view.

git log –since=”3 days ago” – shows all commits for 3 days.

git log — text.txt – shows commits for the current file.

git log –follow — file.txt – shows a history of commits for a file that was renamed.

(Visited 43 times, 1 visits today)

Leave a comment

Your email address will not be published. Required fields are marked *