

{"id":120286,"date":"2023-10-19T19:00:07","date_gmt":"2023-10-19T13:30:07","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=120286"},"modified":"2023-10-19T19:14:00","modified_gmt":"2023-10-19T13:44:00","slug":"git-commands","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/git-commands\/","title":{"rendered":"GIT Commands"},"content":{"rendered":"<p>Git is an effective version control tool that aids developers in effectively managing and tracking changes to their code. Learning key Git commands is critical for streamlining your development workflow, regardless of your level of experience. We&#8217;ll look at the most important and often used Git commands in this blog post, which every developer should be familiar with.<\/p>\n<h2>What is GIT?<\/h2>\n<p>In today&#8217;s software development landscape, Git emerges as a versatile version control system aimed at simplifying the tracking of changes in computer files. The concept of a &#8220;version control system&#8221; inherently implies a tool capable of meticulously recording every modification made to a file or dataset. This functionality becomes a pivotal asset, enabling easy retrieval of specific versions whenever the need arises. Consequently, this intrinsic capability fosters smooth collaboration, particularly within expansive projects.<\/p>\n<p>Git&#8217;s prowess extends to facilitating seamless teamwork among multiple contributors engaged in a project. Its role extends beyond just programmers; even non-technical users can harness its capabilities to efficiently oversee their project files.<\/p>\n<p><strong>Delving into the Git ecosystem reveals two fundamental repositories:<\/strong><\/p>\n<ul>\n<li><strong>Local Repository:<\/strong> Nestled within the confines of our own computer, the local repository comprehensively houses all project files and directories. It serves as our creative space for effecting changes, reviewing historical updates, and committing revisions offline.<\/li>\n<li><strong>Remote Repository:<\/strong> Positioned on a server, the remote repository&#8217;s physical location is not restricted to any specific geographic area. It operates as a shared hub, enabling team members to exchange and synchronize their collective modifications.<\/li>\n<\/ul>\n<p>These repositories function harmoniously, each accompanied by a set of distinct commands. Git offers an array of commands, each tailored to interact with specific repository types, whether local or remote. Through Git&#8217;s seamless orchestration, the intricate choreography of version control transforms into a collaborative symphony, ensuring efficient project management and coordination.<\/p>\n<h3>Commands<\/h3>\n<h4>1. git add:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-add.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120802 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-add.webp\" alt=\"git add\" width=\"566\" height=\"65\" \/><\/a><\/p>\n<p>Changes made by this command are transferred from the working directory to the staging area. Before committing your modifications to the official history, it enables you to prepare a snapshot of your changes. The staging area serves as a transitional stage from the working directory to the commit.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git add README.md<\/pre>\n<h4>2. git branch:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-branch.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120803 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-branch.webp\" alt=\"git branch\" width=\"420\" height=\"52\" \/><\/a><\/p>\n<p>The Git branch is a general-purpose branch administration tool that lets you build separate development environments inside of a single repository. You can work on various features or problem fixes independently thanks to its ability to create, list, remove, and manage branches.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git branch<\/pre>\n<h4>3. git checkout:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-checkout.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120822 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-checkout.webp\" alt=\"git checkout\" width=\"383\" height=\"55\" \/><\/a><\/p>\n<p>In addition to navigating existing branches, git checkout is used to check out previous commits and file revisions. To work on a certain line of development or to swap between branches, use it.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git checkout &lt;NAME&gt;<\/pre>\n<h4>4. git clean:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-clean.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120804 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-clean.webp\" alt=\"git clean\" width=\"760\" height=\"431\" \/><\/a><\/p>\n<p>Untracked files can be removed from the working directory with this command. Git clean lets you organise your working directory by eliminating unneeded files, in contrast to git reset, which normally works on tracked files.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git clean -i<\/pre>\n<h4>5. git clone:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-clone.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120805 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-clone.webp\" alt=\"git clone\" width=\"650\" height=\"140\" \/><\/a><\/p>\n<p>Git clone is used to make a copy of an existing Git repository. The most typical method for giving developers access to a working copy of a central repository so they may interact and make contributions to the project is using this method.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git clone &lt;link&gt;<\/pre>\n<h4>6. git commit:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-commit.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120806 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-commit.webp\" alt=\"git commit\" width=\"701\" height=\"265\" \/><\/a><\/p>\n<p>You can use git commit to take a snapshot of your code and save it to the project history after staging your changes using git add. This outlines the fundamental procedure for all Git users and enables you to monitor the advancement of your project.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git commit<\/pre>\n<h4>7. git config:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/gif-config.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120821 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/gif-config.webp\" alt=\"gif config\" width=\"582\" height=\"106\" \/><\/a><\/p>\n<p>Set configuration parameters for your Git installation with this command. It lets you change things like your name and email address in your Git environment.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git config \u2013global user.name \u201cYourName\u201d\r\ngit config \u2013global user.email \u201cYourEmail\u201d<\/pre>\n<h4>8. git fetch:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-fetch.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120807 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-fetch.webp\" alt=\"git fetch\" width=\"531\" height=\"51\" \/><\/a><\/p>\n<p>Fetching downloads a branch and all of its related files and commits from another repository. You can examine changes before merging them with your project because it doesn&#8217;t integrate anything into your local repository.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git fetch origin<\/pre>\n<h4>9. git init:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-in-it.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120808 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-in-it.webp\" alt=\"git in it\" width=\"667\" height=\"70\" \/><\/a><\/p>\n<p>When putting a project under revision control, the first command you must understand is git init. In the project directory, it starts a fresh Git repository.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git init<\/pre>\n<h4>10. git log:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-log.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120809 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-log.webp\" alt=\"git log\" width=\"512\" height=\"52\" \/><\/a><\/p>\n<p>You can look at a project&#8217;s earlier revisions using Git log. It offers numerous formatting options for committed snapshot displays, allowing you to efficiently review the commit history.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git log<\/pre>\n<h4>11. git merge:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-merge.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120810 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-merge.webp\" alt=\"git merge\" width=\"505\" height=\"46\" \/><\/a><\/p>\n<p>Git merge is an effective technique for combining changes from different branches. After forking a project using a git branch, you can use it to piece its history back together.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git merge master<\/pre>\n<h4>12. git pull:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-pull.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120811 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-pull.webp\" alt=\"git pull\" width=\"698\" height=\"201\" \/><\/a><\/p>\n<p>The automatic equivalent of git fetch and git merge is pulling. It immediately merges a branch that was downloaded from a remote repository into the one that is currently in use.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git pull<\/pre>\n<h4>13. git push:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-push.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120812 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-push.webp\" alt=\"git push\" width=\"520\" height=\"43\" \/><\/a><\/p>\n<p>Pushing is a convenient method for publishing contributions because it enables you to migrate a local branch to another repository. A number of commits are sent to the remote repository.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git push origin master<\/pre>\n<h4>14. git rebase:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-rebase.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120813 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-rebase.webp\" alt=\"git rebase\" width=\"720\" height=\"215\" \/><\/a><\/p>\n<p>You can shift branches around with rebasing, which helps you avoid making unnecessary merging commits. The linear history that results is frequently much simpler to comprehend and study.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git rebase<\/pre>\n<h4>15. git rebase -i:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-rebase-i.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120814 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-rebase-i.webp\" alt=\"git rebase i\" width=\"722\" height=\"213\" \/><\/a><\/p>\n<p>An interactive rebasing session can be started by specifying the -i switch. This gives you more control over the rebasing process because you may add, amend, or delete commits as you go.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git rebase -i<\/pre>\n<h4>16. git reflog:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-reflog.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120815 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-reflog.webp\" alt=\"git reflog\" width=\"493\" height=\"48\" \/><\/a><\/p>\n<p>Git uses a tool called reflog to keep track of changes made to the tips of branches. This enables you to return to changesets even if no branch or tag has referred to them.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git reflog<\/pre>\n<h4>17. git remote:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-remote.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120816 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-remote.webp\" alt=\"git remote\" width=\"716\" height=\"211\" \/><\/a><\/p>\n<p>A useful tool for managing remote connections is git remote. It enables you to execute fetch, pull, and push instructions with more useful shortcuts.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git remote add origin<\/pre>\n<h4>18. git reset:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-reset.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120817 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-reset.webp\" alt=\"git reset\" width=\"508\" height=\"55\" \/><\/a><\/p>\n<p>Git reset undoes changes to files in the working directory. You can use it to clean up or completely remove changes that have not been pushed to a public repository.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git reset \u2013mixed<\/pre>\n<h4>19. git revert:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-revert.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120818 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-revert.webp\" alt=\"git revert\" width=\"827\" height=\"435\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400\">Git revert undoes a committed snapshot, providing a safe and easy way to completely remove a faulty commit from the code base.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git revert<\/pre>\n<h4>20. git status:<\/h4>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-status-1.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-120823 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-status-1.webp\" alt=\"git status\" width=\"797\" height=\"253\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400\">This command displays the state of the working directory and the staged snapshot. Running git status in conjunction with git add and git commit allows you to see exactly what will be included in the next snapshot.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">git status<\/pre>\n<h3>Getting and Creating Projects<\/h3>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400\">Command\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">Description<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git init<\/span><\/td>\n<td><span style=\"font-weight: 400\">Initialize a local Git repository<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git clone ssh:\/\/git@github.com\/[username]\/[repository-name].git<\/span><\/td>\n<td><span style=\"font-weight: 400\">Create a local copy of a remote repository<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Basic Snapshotting<\/h3>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400\">Command\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">Description<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git status<\/span><\/td>\n<td><span style=\"font-weight: 400\">Check status<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git add [file-name.txt]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Add a file to the staging area<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git add -A<\/span><\/td>\n<td><span style=\"font-weight: 400\">Add all new and changed files to the staging area<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git commit -m &#8220;[commit message]&#8221;<\/span><\/td>\n<td><span style=\"font-weight: 400\">Commit changes<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git rm -r [file-name.txt]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Remove a file (or folder)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Branching and Merging<\/h3>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400\">Command<\/span><\/td>\n<td><span style=\"font-weight: 400\">Description<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git branch<\/span><\/td>\n<td><span style=\"font-weight: 400\">List branches (the asterisk denotes the current branch)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git branch -a<\/span><\/td>\n<td><span style=\"font-weight: 400\">List all branches (local and remote)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git branch [branch name]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Create a new branch<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git branch -d [branch name]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Delete a branch<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git push origin &#8211;delete [branch name]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Delete a remote branch<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git checkout -b [branch name]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Create a new branch and switch to it<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git checkout -b [branch name] origin\/[branch name]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Clone a remote branch and switch to it<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git branch -m [old branch name] [new branch name]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Rename a local branch<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git checkout [branch name]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Switch to a branch<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git checkout &#8211;<\/span><\/td>\n<td><span style=\"font-weight: 400\">Switch to the branch last checked out<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git checkout &#8212; [file-name.txt]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Discard changes to a file<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git merge [branch name]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Merge a branch into the active branch<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git merge [source branch] [target branch]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Merge a branch into a target branch<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git stash<\/span><\/td>\n<td><span style=\"font-weight: 400\">Stash changes in a dirty working directory<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git stash clear<\/span><\/td>\n<td><span style=\"font-weight: 400\">Remove all stashed entries<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Sharing and Updating Projects<\/h3>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400\">Command<\/span><\/td>\n<td><span style=\"font-weight: 400\">Description<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git push origin [branch name]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Push a branch to your remote repository<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git push -u origin [branch name]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Push changes to remote repository (and remember the branch)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git push<\/span><\/td>\n<td><span style=\"font-weight: 400\">Push changes to remote repository (remembered branch)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git push origin &#8211;delete [branch name]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Delete a remote branch<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git pull<\/span><\/td>\n<td><span style=\"font-weight: 400\">Update local repository to the newest commit<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git pull origin [branch name]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Pull changes from remote repository<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git remote add origin ssh:\/\/git@github.com\/[username]\/[repository-name].git<\/span><\/td>\n<td><span style=\"font-weight: 400\">Add a remote repository<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git remote set-url origin ssh:\/\/git@github.com\/[username]\/[repository-name].git<\/span><\/td>\n<td><span style=\"font-weight: 400\">Set a repository&#8217;s origin branch to SSH<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Inspection and Comparison<\/h3>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400\">Command<\/span><\/td>\n<td><span style=\"font-weight: 400\">Description<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git log<\/span><\/td>\n<td><span style=\"font-weight: 400\">View changes<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git log &#8211;summary<\/span><\/td>\n<td><span style=\"font-weight: 400\">View changes (detailed)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git log &#8211;oneline<\/span><\/td>\n<td><span style=\"font-weight: 400\">View changes (briefly)<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">git diff [source branch] [target branch]<\/span><\/td>\n<td><span style=\"font-weight: 400\">Preview changes before merging<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Conclusion<\/h3>\n<p>These are some of the most commonly used Git commands that every developer should be familiar with. Mastering these commands will empower you to work efficiently with version control, collaborate seamlessly with your team, and manage your projects effectively. Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Git is an effective version control tool that aids developers in effectively managing and tracking changes to their code. Learning key Git commands is critical for streamlining your development workflow, regardless of your level&#46;&#46;&#46;<\/p>\n","protected":false},"author":581,"featured_media":120288,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27914],"tags":[28393,28392,28391],"class_list":["post-120286","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-git-tutorials","tag-basic-git-commands","tag-commands-in-git","tag-git-commands"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>GIT Commands - DataFlair<\/title>\n<meta name=\"description\" content=\"Mastering these commands will empower you to work efficiently with version control, collaborate seamlessly with your team.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/git-commands\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"GIT Commands - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Mastering these commands will empower you to work efficiently with version control, collaborate seamlessly with your team.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/git-commands\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-19T13:30:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-19T13:44:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-commands.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"GIT Commands - DataFlair","description":"Mastering these commands will empower you to work efficiently with version control, collaborate seamlessly with your team.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/git-commands\/","og_locale":"en_US","og_type":"article","og_title":"GIT Commands - DataFlair","og_description":"Mastering these commands will empower you to work efficiently with version control, collaborate seamlessly with your team.","og_url":"https:\/\/data-flair.training\/blogs\/git-commands\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2023-10-19T13:30:07+00:00","article_modified_time":"2023-10-19T13:44:00+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-commands.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/git-commands\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/git-commands\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445"},"headline":"GIT Commands","datePublished":"2023-10-19T13:30:07+00:00","dateModified":"2023-10-19T13:44:00+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/git-commands\/"},"wordCount":1423,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/git-commands\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-commands.webp","keywords":["basic git commands","commands in git","git commands"],"articleSection":["Git Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/git-commands\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/git-commands\/","url":"https:\/\/data-flair.training\/blogs\/git-commands\/","name":"GIT Commands - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/git-commands\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/git-commands\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-commands.webp","datePublished":"2023-10-19T13:30:07+00:00","dateModified":"2023-10-19T13:44:00+00:00","description":"Mastering these commands will empower you to work efficiently with version control, collaborate seamlessly with your team.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/git-commands\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/git-commands\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/git-commands\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-commands.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/git-commands.webp","width":1200,"height":628,"caption":"git commands"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/git-commands\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Git Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/git-tutorials\/"},{"@type":"ListItem","position":3,"name":"GIT Commands"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam6\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/120286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=120286"}],"version-history":[{"count":5,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/120286\/revisions"}],"predecessor-version":[{"id":122786,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/120286\/revisions\/122786"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/120288"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=120286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=120286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=120286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}