Git Commands

Git Commands

Version control system to make life easier

Introduction

GIT is a version control system that enables individuals or teams to collaborate and work with the same code on a local or remote repository. Git isn't just for programmers--users can check out files, modify them and check them back in. Any document can be collaborated on in this version control system. Git can be used from within a text-based terminal window or one of the many GUI Git clients. Git is also a handy way to install applications from source on Linux.

GIT is most used versioning tool in most of the companies. It was earlier considered as a added advantage if developer has the knowledge but gradually it becomes a mandatory requirement to know. The day I started by career in 2013 to till date all the companies which I worked with use GIT as the versioning tool. Even though it's mandatory some of it's qualities/capabilities are overlooked as developers don't concentrate much more than the normal commands. I have even encountered senior developers with immense experience (2x of my total experience) struggle to solve a normal merge issue. In this article I will cover the widely used commands mostly by developers during development

Commonly used GIT Commands

Turn an existing directory into a git repository

git init

Clone (download) a repository that already exists on GitHub, including all of the files, branches, and commits

git clone [url]

Sets the name you want attached to your commit transactions

git config --global user.name "[name]"

Sets the email you want attached to your commit transactions

git config --global user.email "[email address]"

Creates a new branch

git branch [branch-name]

Switches to the specified branch and updates the working directory

git checkout [branch-name]

Combines the specified branch’s history into the current branch. This is usually done in pull requests, but is an important Git operation

git merge [branch]

Deletes the specified branch

git branch -d [branch-name]

Downloads all history from the remote tracking branches

git fetch --all

Updates your current local working branch with all new commits from the corresponding remote branch on GitHub. git pull is a combination of git fetch and git merge

git pull

Uploads all local branch commits to GitHub

git push

Undoes all commits after [commit], preserving changes locally

git reset [commit]

Discards all history and changes back to the specified commit

git reset --hard [commit]

Records file snapshots permanently in version history

git commit -m "[descriptive message]"

Snapshots the file in preparation for versioning

git add [file]

To cache the latest code which is not committed

git stash

Command to merge and pull

git rebase

References / Source / Credits:

  1. git-scm.com
  2. training.github.com/downloads/github-git-ch..