GIT essentials quick walkthrough — use in your daily life!!!

Introduction

Git (/ɡɪt/) is a widely-used version control system for software development. It is a distributed revision control system with an emphasis on speed, data integrity, and support for distributed, non-linear workflows. Git allows groups of people to work on the same documents (often code) at the same time, and without stepping on each other’s toes. https://git-scm.com/


Create Repository

Start new repository or obtain one from existing URL.

  • $ git init [project-name] Crates new Local repository with specified name [project-name].
  • $ git clone [url] Downloads a project and its entire version history. If you have access to private repository it’s better to use SSH URL instead of HTTP/HTTPS so that you don’t need to authorization for any interaction to remote repository. SSH key can be generated using command, $cmd: ssh-keygen -t rsa more

Configure GIT User

Configure user information,signature for all local repositories.

  • $ git config — — global user.name “[name]” Sets name you want to attach for all your commit transactions.
  • $ git config — — global user.email “[email address]” Sets email you want to attach for all your commit transactions.
  • $ git config — — global color.ui Auto enables helpful colorization of command line output, gives better visual indication for different output parameters.

Make Changes

Review edits and work on commit transaction.

  • $ git status Lists all new or changed files yet to be committed.
  • $ git add [file-name] File will be ready for commit, snapshots for versioning.
  • $ git reset [file-name] Unstage the file, but keep its content, file removed from commit.
  • $ git diff Shows the differences not yet committed.
  • $ git diff — — staged Shows difference between staging and last file version.
  • $ git commit -m “[detailed message]” Records file snapshots permanently in revision history with “[detailed message]” as tag description, so always give meaningful message to your commits so that viewing history won’t make you lost.

Group Changes

Name a series of changes, a lightweight movable pointer to set of commits.

  • $ git branch Lists all local branch in current repository.
  • $ git branch [branch-name] Creates new branch only.
  • $ git checkout -b “[branch-name]” Creates new branch [branch-name] and switches to branch [branch-name].
  • $ git merge [branch-name] Merges all changes from branch [branch-name] to current branch, combines history to current branch as well.
  • $ git branch -d [branch-name] Deletes the specified branch [branch-name].

Refactor file names

Find and remove versioned files.

  • $ git rm [file-name] Delete file from working directory and stages deletion.
  • $ git rm — — cached [file-name] Remove file from version control but keep it locally.
  • $ git mv [file-original] [file-renamed] Renaming the file and prepare commit.

Review version history

Browse and inspect evolution of project files in version.

  • $ git log Lists version history for current branch.
  • $ git log — — follow [file-name] Lists all version history for a file, including renames.
  • $ git diff [first-branch] [second-branch] Shows content difference between [first-branch] and [second-branch].
  • $ git show [commit] Shows metadata and content for specified commit. You can refer to commit with SHA-1 hash that it’s given, for above command you can use Short SHA-1 also.

Redecorate/Redo Commits

Erase mistakes or craft replacement history.

  • $ git reset [commit] Undoes all commit changes after [commit] and stores changes locally.
  • $ git reset — — hard [commit] Discards all history and changes aback to specified commit.

Save snippets

Shelve and restore incomplete changes.

  • $ git stash Temporarily stores all modified tracked files locally.
  • $ git stash list Lists all stashed change sheets.
  • $ git stash pop Restores most recently stashed files in current version.
  • $ git stash drop Discards most recently stashed change sheet.

Synchronize changes

Register a repository bookmark and exchange version history.

  • $ git fetch [bookmark] Download all history from the repository bookmark [bookmark].
  • $ git push [remote-name] [branch-name] Updates all local branch commits to remote branch [branch-name].
  • $ git pull Downloads bookmark history and incorporates changes.

File status flags

File status file are shown against each file when you do $ git status .

  • M modified File has been modified.
  • C copy-edit File has been copied and modified.
  • R rename-edit File has been renamed and modified.
  • A added File has been added.
  • D deleted File has been deleted.
  • U unmerged File has conflicts after merge.

Great online tool for get started with basics of git commands https://try.github.io/levels/1/challenges/1

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.