Git essential commands
Git essential commands
In this article we will explore git and some important commands to use Git. As you know Git is used for version control. There are some commands that are used by developers on daily basis while committing. Here are some useful Git commands.
Make Changes
Initializing a git repository. (To create a new git repository).
git init
Lists all new or modified files to be committed
git status
Shows the file differences not yet staged
git diff
Snapshots the file in preparation for versioning
git add <filename>
Shows file differences between staging and the last file version
git diff --staged
Unstages the file, but preserves its contents
git reset <filename>
Committing a file – File snapshots permanently in version history. We have to add a message describing the change made.
$ git commit - m "Added new registration form"
Configuration
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"
Enables helpful colorization of command line output
git config --global color.ui auto
Creating Repositories
Start a new repository or obtain one from an existing URL
Creates a new local repository with the specified name
$ git init project-name
Downloads a project and its entire version history
git clone <url>
Git Branches
Name a series of commits and combine completed efforts
Lists all local branches in the current repository
git branch
Switches to the specified branch and updates the working directory
git branch branch-name
Combines the specified branch’s history into the current branch
git merge branch
Deletes the specified branch
git branch -d branch- name
Synchronize Changes
Register a repository bookmark and exchange version history
Downloads all history from the repository
git fetch bookmark
Combines bookmark’s branch into current local branch
git merge bookmark/branch
Uploads all local branch commits to GitHub
git push alias branch
Refactor Filename
Relocate and remove versioned files
Deletes the file from the working directory and stages the deletion
git rm file
Removes the file from version control but preserves the file locally
git rm --cached file
Changes the file name and prepares it for commit
git mv file-original file-renamed
Save Fragments
Shelve and restore incomplete changes
Temporarily stores all modified tracked files
git stash
Lists all stashed changesets
git stash list
Restores the most recently stashed files
git stash pop
Discards the most recently stashed changeset
git stash drop
Redo Commits
Erase mistakes and craft replacement history
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
Review History
Browse and inspect the log history of project files
Lists version history for the current branch
git log
file Lists version history for a file, including renames
git log --follow
Shows content differences between two branches
git diff first-branch...second-branch
Outputs metadata and content changes of the specified commit
git show commit
These are some basic commands used by developers in their day to day work. thanks for reading and do visit again to have more inflammatory articles.