If you are just getting started with git then you could easily get lost in the maze of all the different available commands.
A more useful approach, perhaps, is to concentrate on a core of major git commands, which will allow you to complete some useful work while gradually adding more commands to your git vocabulary.
The commands you need will depend upon your role in the team and whether you are an individual, or standalone, developer; a participant in a team project or an integrator.
Here are some core commands that are useful in all of these roles.
Git Commands for standalone or individual developer
An individual developer works alone with a single repository and doesn’t need to exchange patches with others.
These are some core commands that will be useful from the start.
The git-init command is used to create a new repository, which is empty and contains a git directory and sub directories for various assets.
Git-show-branch will show you where you are in terms of branches and commits. The git-checkout and git-branch commands allow you to manage and switch beneath branches, while the git-log provides a log of all commits and can be used with options to find specific commit attributes.
Git-add is used to manage the index file and the git-diff and git-status commands show changes and status of the working tree.
Git-commit will record changes to the repository and git-merge is used to join different development histories.
The git-tag command will add or manage tag references.
Git Commands for participants
Working with others as a participant or integrating others’ work will require some additional git commands.
The git-clone command allows you to clone a repository into a new directory, while the git-pull and git-fetch commands are used to fetch from and merge with other repositories or branches.
The git-push command, meanwhile, is useful in updating remote refs and any associated objects.
The git-format-patch command will prepare your patches for an e-mail submission. This is relevant for those working with a version of the Linux kernel type of public workflow.
Common integrator commands
The integrator is a crucial role in a group project, being the person who receives, reviews and integrates changes.
Commands specific to this role include git-am, which takes information from mailbox messages and splits it into a commit log message, with information on authorship and patches.
Git-pull will incorporate changes from remote repositories into the current branch, allowing you to merge from trusted team members.
Git-format-patch is again used to prepare patches for email submission and git-revert is always useful to undo any botched commits.
Git push will update remote refs and their associated objects.
Building your git vocabulary
Without being exhaustive, these common commands provide you with a basic git vocabulary in each of the main team roles.
Every user will, undoubtedly, develop an understanding of additional commands as their experience and confidence grows but it is surprising just how much can be achieved with a small core of commands.