
While working on a big project with a developer team, we use version control which keeps track of the project code and maintains all the versions of it so even if we want to roll back to the previous version we would do that easily.
If we do not use a version control we would not be able to manage project version properly, for example, if we create a new project which contains a lot of files, after a week we want to add some new functionality we would add some new code or edit some code in the previous file and create a new version of that project. This all process of changing or modifying the previous version of projects can be tracked by version control so other developers which are working on the same project can see what changes have been made on the project and what was the previous code. Git is the most popular, fast and scalable version control, and it works on commands, here in this article we have provided some of the most important Git commands that you should know if you want to use Git. Here we have not covered all the commands of Git because there are hundreds of Git commands and it is impossible to go through each one and learn them so we focus on the important ones which are enough to serve our purpose.
What is Git?
Git is an Open Source Distributed Version Control System(DVCS), it is an application or program which keeps track of your project version and helps you to manage the project. It is a Distributed version control here distributed means all the members of a team that are working on the same project would have the complete version of the project.
Git Features
- Keep track of project files
- Track all the changes made in the project
- Record all the changes
- It can restore the old version of Project
- Help to compare the new code and old code
- Distribute the same project to different developers
- Merge code from a different computer.
Git Commands
Here we are sharing a curated list of Git Commands which are executing by the developers on a day to day basis:
Git Command | Description |
git add | This command adds all the new files to the initialize repository |
git archive | This command can create a zip or tar file of the content from your repository. |
git branch | This command print all the branch linked to that repository. |
git branch branch_name | This command will add a new branch to the repository with name branch_name |
git checkout | With checkout command, we can switch from one branch to another branch |
git clone
example: git clone [urls] |
Using this command you can clone an existing repository or directory to your system. |
git commit –m “message” | The commit command record the file in the previous version |
git config
example: git config –global user.name “Username” git config –global user.email “useremail@” |
This command is used to set the author’s username and email address when the commit is done. |
git diff | The diff command is used to show the difference of the files which are not staged |
git fetch [url] | Download object from another repository |
git –help | Print the most commonly used commands |
git init
example: git init [directory name] |
This command is used to initialize a new directory or repository to the git. |
git log | This command is used to print the list of all the version history |
git merge | This command can be used to merge any branch with the current branch. |
git mv filename | This command is used to move or rename any file, directory or a symlink |
git pull repository_url | This command is work just opposite of push command, with this command you can bring the changes in your local repository if anyone had made changes on the remote repository. |
git push
example: git push origin master |
With push command we can push or commit changes in the master branch, that will reflect on your remote repository. |
git remote | This command can connect your repository with the remoter server. |
git reset | The reset command is the opposite of commit command and undoes the commit statements. |
git rm filename | The rm stands for removal, and this command is used to remove a specific file from the repository. |
git show | This command is used to show all the objects of the directory, it simply shows all present code. |
git status | The status command used to list all the files which have been committed. |
git tag commit_ID | With tag command, we can tag some specific commits. |
git –version | Show the git suite version. |
git-add | Add a net content to the index |
Summary
There are hundreds of git commands, here we have provided only a few of them if you use git as version control for your project so these are the most common commands you would use frequently. When you use git you do not need to learn each command just learn the basic ones and those are enough to serve your purpose.
The most common git commands:
To set a repository
- git init
- git clone
To make changes on the files
- git add
- git mv
- git reset
- git rm
To check the history
- git bisect
- git grep
- git log
- git show
- git status
To grow and mark the changes or history
- git branch
- git checkout
- git commit
- git diff
- git merge
- git tag
To work in collaboration
- git push
- git pull
- git fetch
You may also be interested in:
Super really very usefull thanku so much, especially starting intro