• Tutorials Logic, IN
  • +91 8092939553
  • info@tutorialslogic.com

Git Quick Overview


Git VCS
What is Git ?

Git is a leading, free, open source, distributed, most powerful and most commonly used version control system (VCS), which is designed by Linus Torvalds for tracking changes in source code during software development. It is mainly design for coordinating work among programmers to handle everything from small to very large projects with speed and efficiency.

Here is a list of some common Git commands that can help you quickly perform various tasks:


Configuration

git config --global user.name "Your Name": Sets your username.

git config --global user.email "you@example.com": Sets your email.

git config --global core.editor "editor": Sets the default text editor.


Creating and Cloning Repositories

git init: Initializes a new Git repository.

git clone <repo_url>: Clones an existing repository.


Basic Operations

git status: Shows the working directory status.

git add <file>: Stages a file.

git add .: Stages all changes.

git commit -m "Commit message": Commits staged changes.

git commit -a -m "Commit message": Commits all changes (staged and unstaged).

git push: Pushes changes to the remote repository.

git pull: Fetches and merges changes from the remote repository.

git fetch: Fetches changes from the remote repository without merging.

git merge <branch>: Merges the specified branch into the current branch.


Branching

git branch: Lists branches.

git branch <branch_name>: Creates a new branch.

git checkout <branch_name>: Switches to the specified branch.

git checkout -b <branch_name>: Creates and switches to a new branch.

git branch -d <branch_name>: Deletes a branch.

git branch -D <branch_name>: Forcefully deletes a branch.


Viewing History

git log: Shows commit history.

git log --oneline: Shows a compact commit history.

git log --graph: Shows commit history as a graph.

git log --stat: Shows commit history with file changes.


Stashing

git stash: Stashes changes.

git stash apply: Applies stashed changes.

git stash pop: Applies and removes stashed changes.

git stash list: Lists stashes.

git stash drop: Deletes a stash.


Remote Repositories

git remote: Lists remote repositories.

git remote -v: Lists remote repositories with URLs.

git remote add <name> <url>: Adds a new remote repository.

git remote remove <name>: Removes a remote repository.

git remote set-url <name> <newurl>: Changes the URL of a remote repository.


Resetting and Reverting

git reset <file>: Unstages a file.

git reset --hard: Resets the working directory and index to the last commit.

git revert <commit>: Reverts a commit by creating a new commit.

git reset --soft <commit>: Moves the current branch tip to a specified commit, but does not reset the working directory.


Tagging

git tag: Lists tags.

git tag <tagname>: Creates a new tag.

git tag -a <tagname> -m "Message": Creates an annotated tag.

git push origin <tagname>: Pushes a tag to the remote repository.

git push --tags: Pushes all tags to the remote repository.


Miscellaneous

git diff: Shows changes between commits, commit and working directory, etc.

git diff --staged: Shows changes between staged changes and the last commit.

git blame <file>: Shows who changed each line of a file and when.

git show <commit>: Shows details of a commit.