Essential git commands

Git is a free distributed version-control system to track changes in source code. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files.

In this post I have tried to summarize the most important git commands.


git config

To set your user name and email in the main configuration file.
https://git-scm.com/docs/git-config


git init

To initialise a git repository in the current directory.
command: git init
https://git-scm.com/docs/git-init

git clone

To copy a git repository from remote source.
command: git clone <git_url>
https://git-scm.com/docs/git-clone

git status

To check the pending changes in the working directory
command: git status
https://git-scm.com/docs/git-status

git add

To add changes to staging area
command: git add .
command: git add -p (for an interactive view of what you've made changes on)https://git-scm.com/docs/git-add

git commit

To save changes in the local repository
command: git commit - m "commit_description"
https://git-scm.com/docs/git-commit

git push/pull

To update your repository with the changes from remote (git pull)
To upload the changes commited in your repository to remote (git push)
command: git pull/push
https://git-scm.com/docs/git-pull
https://git-scm.com/docs/git-push

git branch

To list all the branches
command: git branch
https://git-scm.com/docs/git-branch

git checkout

To switch between your branches or to discard all the uncommited changes
command: git checkout <branch_name> (change to the specified branch)
command: git checkout . (discard all changes from your current branch)
https://git-scm.com/docs/git-checkout

git stash

To save changes that you don't want to commit inmediatly.
command: git stash (store changes in stash)
command: git stash pop (move changes from stash and delete them in stash)
command: git stash apply (move changes from stash and keep them in stash)
https://git-scm.com/docs/git-stash

git merge

To merge the changes from the specified branch in the current branch
command: git merge <branch_name>
https://git-scm.com/docs/git-merge

git reset

To set the index to the latest commit
command: git merge <branch_name>
https://git-scm.com/docs/git-reset

git remote

To check what remote/source you have or add a new remote.
command: git remote (to check and list)
command: git remote add <remote_url> (to add a new remote)https://git-scm.com/docs/git-remote

git diff

To review changes before committing a change
command: git diff
https://git-scm.com/docs/git-diff

git log

To show commit logs
command: git log --graph (to see the classic git branch timeline view)
https://git-scm.com/docs/git-log


Would you add any other useful command?

Comentarios