Git Basics: A Beginner’s Guide to the Most Common Commands

Git Command

Git Commands

git config

This command sets the author name and email address respectively to be used with your commits.1git config –global user.name “[name]” 2git config –global user.email “[email address]”

git init

This command is used to start a new repository.1git init [repository name]

git clone

This command is used to obtain a repository from an existing URL.1git clone [url]

git add

This command adds a file to the staging area.1git add [file]

This command adds one or more to the staging area.1git add *

git commit

This command records or snapshots the file permanently in the version history.1git commit -m “[ Type in the commit message]”

This command commits any files you’ve added with the git add command and also commits any files you’ve changed since then.1git commit -a

git diff

This command shows the file differences which are not yet staged.1git diff

This command shows the differences between the files in the staging area and the latest version present.1git diff –staged

This command shows the differences between the two branches mentioned.1git diff [first branch] [second branch]

git reset

This command unstages the file, but it preserves the file contents.1git reset [file]

This command undoes all the commits after the specified commit and preserves the changes locally.1git reset [commit]

This command discards all history and goes back to the specified commit.1git reset –hard [commit]

git status

This command lists all the files that have to be committed.1git status

git rm

This command deletes the file from your working directory and stages the deletion.1git rm [file]

git log

This command is used to list the version history for the current branch.1git log

This command lists version history for a file, including the renaming of files also.1git log –follow[file]

git show

This command shows the metadata and content changes of the specified commit.1git show [commit]

git tag

This command is used to give tags to the specified commit.1git tag [commitID]

git branch

This command lists all the local branches in the current repository.1git branch

This command creates a new branch.1git branch [branch name]

This command deletes the feature branch.1git branch -d [branch name]

git checkout

This command is used to switch from one branch to another.1git checkout [branch name]

This command creates a new branch and also switches to it.1git checkout -b [branch name]

git merge

This command merges the specified branch’s history into the current branch.1git merge [branch name]

git remote

This command is used to connect your local repository to the remote server.1git remote add [variable name] [Remote Server Link]

git push

This command sends the committed changes of master branch to your remote repository.1git push [variable name] master

This command sends the branch commits to your remote repository.1git push [variable name] [branch]

This command pushes all branches to your remote repository.1git push –all [variable name]

This command deletes a branch on your remote repository.1git push [variable name] :[branch name]

git pull

This command fetches and merges changes on the remote server to your working directory.1git pull [Repository Link]

git stash

This command temporarily stores all the modified tracked files.1git stash save

This command restores the most recently stashed files.1git stash pop

This command lists all stashed changesets.1git stash list

This command discards the most recently stashed changeset.1git stash drop

Related posts

Leave a Comment