Useful git commands that every developer should know
Git
is a open source version control system to manage large scale or small scale projects. If your team is using Git, you do not have to train new hires on your workflow, because they’ll already be familiar with distributed development. Unlike SVN, Git is distributed version control system which generated local copy of remote repository into local for each developer. Merging and managing multiple branches is quite easy. Here are some useful git commands each developer need to know before using git.
git init
is used to initialise repository in local system. It’s very first command to start working with git.
It updates change to local repository from remote repository.
git commit
command is used to save changes in your local system with note.
Syntax:git commit -m "[Your message]"
This command is used to add files to commit changes on local repository. It also allows you to add multiple files at a time.
Syntax: git add [File path - 1] [File path - 2]
This command is used to update local commits to remote repository.
Syntax:git push origin "[Git Branch Name]"
Steps:
– git add [File path you want to commit]
– git commit -m 'Test commit'
– git pull --rebase
– git push origin master
git status
command shows changes done on local repository. It list out all the files which are modified, deleted or added in local repository.
Syntax: git status
It list out all the branches fetched from remote repository.
Syntax: git branch
git checkout
checkout file or branch from remote repository to local repository.
Syntax:
– git checkout [File Path]
// checkout file
– git checkout [Branch Name]
// checkout branch
fetches data from remote to local repository
Syntax:
– git fetch
This command is used to remove single or multiple files from repository
Syntax:
– git rm [File Path]
Show commit logs with details such as date time on which files commit and tags
Syntax:
– git log
Temporary removes all the uncommited changes from local repository. User can retrieve changes by git stash apply
.
Syntax:
– git stash
Restores stashed changes into local repository.
Syntax:
– git stash apply
There are many more git commands expecting above command. I will update article later with new commands. Don’t forget to share article on social media and your developer friends.