10 Git commands every developer should know

, 10 Git commands every developer should know

Git is open source,free tool which is used in small as well as large scale projects.
Git is more efficient and high speed tool.It was created by Linus Torvalds in 2005 to develop
Linux Kernel.Git is secure tool it uses SHA1(Secure Hash Function) to identify the user within its
repository.
If you are not aware with git commands then following information help you to work with git.

1. git config

Git config is used to configure git username and git email address.
This configuration is used when you commit the code to github.
We can set the configuration on local level and global level.
–local:
By default git config write configuration locally if configuration level is not specified.
Local level configuration details are stored in repository’s git/config file.
–global:
Global level configuration is specify by user.Global level configuration details are stored in
user’s home directory in gitconfig file.

git config –global user.name “[name]”

git config –global user.email “[email address]”

2. git init

Git init is used to create new repository.And it is also used to create existing project as a git project.Just go to project’s directory on Terminal and hit git init command. The command creates .git s ubdirectory​ in project repository.If you found .git s ubdirectory​ in any project means that project is initialize with git .So You can do git operations on that project.

git init [repository name]

3. git clone

Git clone is used to download repository in you machine using URL.
Copy remote repository in your local machine. You can clone any existing GIT repository to your
local machine.

git clone [url]

4. git add

Git add command is used to add files from your local machine to targeted repository.
If you want to add specific file then you can use this command “git add [file]” and If you want to
push more than one file from any directory, just go to that directory from Terminal and use this
command “git add *”.

git add [file]

git add *

5. git commit

Git commit is used to add changes to your local repository. We pass message through git commit what changes we have done in this commit. We include message before we hit git commit command.

git commit -m “<message>”

6. git push

Git push is used to push the committed files to local repository.

git push

7. git status

Git status shows all files which are have to be committed to local repository.

git status

8. git branch

Git branch is used to display all branch name in current repository. If you want to create new branch you can use following command 

git branch <branchName>

If you want to delete any specific branch you can use following command

git branch -d <branchName>

9. git checkout

Git checkout is used to switch one branch to another branch.
If you want to create a new branch and switch it to new branch you can use following command

git checkout -b <branchName>

git checkout

10. git pull

Git pull is used to fetch and merge changes on local directory from remote server.
Git pull downloads changes from remote server to local project directory.

git pull

Leave a Reply