Here is Git basic Commands which every developer should know. It Will Save your time.
git config
Usage: git config –global user.name “[name]”
Usage: git config –global user.email “[email address]”
This command sets the author name and email address respectively to be used with your commits.
git init
Usage: git init [repository name]
This command is used to start a new repository.
git clone
Usage: git clone [url]
This command is used to obtain a repository from an existing URL.
git add
Usage: git add [file]
This command adds one or more to the staging area.
Usage: git add *
This command adds one or more to the staging area.
git commit
Usage: git commit -m “[ Type in the commit message]”
This command records or snapshots the file permanently in the
version history
Usage: git commit -a
This command commits any files you’ve added with the git add command and also commits any files you’ve changed since then.
Usage: git commit -a
This command commits any files you’ve added with the git add command and also commits any files you’ve changed since then.
git diff
Usage: git diff
This command shows the file differences which are not yet staged.
Usage: git diff –staged
This command shows the differences between the files in the staging area and the latest version present.
Usage: git diff [first branch] [second branch]
This command shows the differences between the two branches mentioned.
Usage: git diff –staged
This command shows the differences between the files in the staging area and the latest version present.
Usage: git diff [first branch] [second branch]
This command shows the differences between the two branches mentioned.
git checkout
s a new branch and also switches to it.
git merge
Usage: git merge [branch name]
This command merges the specified branch’s history into the current branch.
git remote
Usage: git remote add [variable name] [Remote Server Link]
This command is used to connect your local repository to the remote server.
git remote
Usage: git remote add [variable name] [Remote Server Link]
This command is used to connect your local repository to the remote server.
git push
Usage: git push [variable name] master
This command sends the committed changes of master branch to your remote repository.
Usage: git push [variable name] [branch]
This command sends the branch commits to your remote repository.
Usage: git push –all [variable name]
This command pushes all branches to your remote repository.
git pull
Usage: git pull [Repository Link]
This command fetches and merges changes on the remote server to your working directory.
git stash
Usage: git stash save
This command temporarily stores all the modified tracked files.
Usage: git stash pop
This command restores the most recently stashed files.
Usage: git stash list
This command lists all stashed changesets.
Usage: git stash drop
This command discards the most recently stashed changeset.
git branch
Usage: git branch
This command create new branch and other commend for check history
Creating a new branch
git branch
git branch fix-division-by-zero-bug2
git branch fix-property-call-on-undefined-object2# Listing all branches
git branch
git branch# Listing remote branches
git branch -a# Renaming an existing branch
git branch -m
git branch fix-division-by-zero-bug2 fix-division-by-zero-bug
git branch call-on-undefined-object2 call-on-undefined-object#
Deleting an existing branch
git branch -d
git branch fix-division-by-zero# Deleting an existing branch even when the branch has not fully been merged in its upstream branch
git branch -D
git branch -D fix property-call-on-undefined-objectCheckout from main branch to a feature-branch
git checkout
git checkout feature-branch# Checkout a branch that is non-existentYou can the flag -b on git checkout to checkout from your current
branch into a new branch
git checkout -b
git checkout -b feature-branch-v2
git reset
Usage (i): git reset Code on git
Move every staged files back into your working tree
git reset# Move only specific staged files back into your working tree
git reset [, , , ...]# Move only staged files in a given folder
git reset
git log
Usage (i): git log
This command is used when we want to check the log for every commit in detail in our repository.
Note: It will show the log of the branch we are in. We can check the last three logs by giving the command: git log -3
Usage (ii): git log –graph
Usage (iii): git log –graph –pretty=oneline
git branch
Usage (i): git branch [name-of-the-branch]
So far, we saw how we can work on Git. Now, imagine, multiple developers working on the same project or repository! To handle the workspace of multiple developers, we can use branches. To create a branch (say, the ‘name-of-the-branch’ is ‘branch1’), we use this command:
Usage (ii): git branch -D [name -of-the-branch]
Similarly, to delete a branch, we use the git branch -D command:
Top comments (0)