GIT COMMANDS EVERY DEVELOPER SHOULD TO KNOW? https://www.9series.com/
WHAT IS GIT??
WHAT IS GIT?? Git is free and open source software for distributed version control: tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during software development. Git means that a local clone of the project is a complete version control repository. These fully functional local repositories make it easy to work offline or remotely.
GIT features
01 Tracks history 02 Free and open source 03 Creates backups 04 Branching is easier 05 Distributed development. Many More... GIT FEATURES GIT features
Git Basic Git clone is a command for downloading existing source code from a remote repository (like Github, for example). In other words, Git clone basically makes an identical copy of the latest version of a project in a repository and saves it to your computer. Git clone git clone <https://name-of-the-repository- link> Cloning a local or remote repository Cloning a bare repository Using shallow options to partially clone repositories Git URL syntax and supported protocols
Git Basic git clone https://github.com/abc/Git-Example.git Clone with HTTPs section
Git Basic git clone https://github.com/abc/Git-Example.git git clone <repo> <directory> Clone with HTTPs section Cloning to a specific folder
Git Basic git clone https://github.com/abc/Git-Example.git git clone <repo> <directory> git clone --branch <tag> <repo> Clone with HTTPs section Cloning to a specific folder Cloning a specific tag
Git Basic git clone -branch new_feature git://remoterepository.git git clone -branch
Git Basic git clone -branch new_feature git://remoterepository.git git clone <repogit clone --template= <template_directory> <repo location> <directory> git clone -branch git clone --template
Git Basic git clone -branch new_feature git://remoterepository.git git clone <repogit clone --template= <template_directory> <repo location> <directory> git clone https://username@github.com/username/repository.git git clone -branch git clone --template git clone git@remote.git git clone https://username:password@github.com/username/repository.git
Git Basic git clone https://<token>@github.com/<username>/<repository>.git Clone the Repo token
Git Basic git clone https://<token>@github.com/<username>/<repository>.git Clone the Repo token Other many why to you can clone your git projects.
HOME One question WORK
HOME Clone multiple git repositories in one local directory? WORK One questions
GitHub Cloud Providers Git GitHub On premises Bitbucket GitLab Cloud GitLab On premises Azure DevOps Git Atlassian Stash (old version of Bibucket Server) Other many providers is available in market.
GIT CONFIG git config user.name "Hitesh" git set username and email git config user.email "abc@gm.co" git config credential.helper store Note : You need to store global git config then you can use bllow command. git config --global user.name / user.email
GIT BASIC COMMANDS Git clone git clone is primarily used to point to an existing repo and make a clone or copy of that repo at in a new directory,
GIT BASIC COMMANDS Git branch The git branch command lets you create, list, rename, and delete branches
GIT BASIC COMMANDS Creating a new branch commit and push: git branch <branch-name> git status git add README.md git add --all git commit -m "Editing the README to try out git add/commit"
GIT BASIC COMMANDS Short status flags are: ?? - Untracked files A - Files added to stage M - Modified files D - Deleted files R - Renamed C - Copied U - Updated but unmerged F - Force Push.
 Other many short flags Short status flags are:
GIT BASIC COMMANDS Creating a new branch commit and push: git commit git push -u <remote> <branch-name>
GIT BASIC COMMANDS Viewing branches: git branch or git branch --list
GIT BASIC COMMANDS Deleting a branch: git branch -d <branch-name>
GIT BASIC COMMANDS Git checkout git checkout <name-of-your-branch>
GIT BASIC COMMANDS Git Pull git pull <remote>
GIT BASIC COMMANDS Git revert A safer way that we can undo our commits is by using git revert. git revert 3321844
GIT BASIC COMMANDS Git merge First you should switch to the dev branch: git checkout dev Before merging, you should update your local dev branch: git fetch
GIT ADVANCE COMMANDS git stash This Git command temporarily stores your modified files. You can work in stashed with the following Git command. git stash Usage And you can view all of your stashes with the following command git stash list And if you need a apply a stash to a branch, simply use apply git stash apply
GIT ADVANCE COMMANDS git rebase Git rebase similar to the git merge command. It integrates two branches into a single branch with one exception. A git rebase command rewrites the commit history.
GIT ADVANCE COMMANDS git rebase Git rebase similar to the git merge command. It integrates two branches into a single branch with one exception. A git rebase command rewrites the commit history. Usage You should use the Git rebase command when you have multiple private branches to consolidate into a single branch. And it will make the commit history linear. git rebase <base>
GIT ADVANCE COMMANDS git cherry-pick Git cherry-pick is a helpful command. It's a robust command and allows you to pick any commit from any branch and apply it to any other branch. Usage git cherry-pick <commit-hash> Git cherry-pick doesn’t modify the history of a repository; instead, it adds to the history.
GIT ADVANCE COMMANDS git archive Git archive command will combine multiple files into a single file. It's like a zip utility, so it means you can extract the archive files to get individual files. Usage git archive --format zip HEAD > archive-HEAD.zip It will create a zip archive of the current revision.
GIT ADVANCE COMMANDS Rewriting history change with amend Git commit --amend and other methods of rewriting history Changing the Last Commit: git commit --amend git commit --amend -m "an updated commit message" git push -f —> It’s use to this is latest code source branch if this command you can’t use then getting error link merge or rebase.
GIT ADVANCE COMMANDS Git tracks changes git reset --hard git reset --hard <SOME-COMMIT> The “--hard” option is used in order to reset the files of the index (or the staging area) and of the working directory. -- hard which will completely destroy any changes and remove them from the local directory.
GIT ADVANCE COMMANDS Git tracks changes git reset --soft HEAD@{1} which will keep your files, and stage all changes back automatically. git reset --mixed HEAD@{1} which is the default, and keeps all files the same but unstages the changes. This is the most flexible option, but despite the name, it doesn’t modify files. git commit -m "Reverting to the state of the project at f414f31" git push -f —> It’s use to this is latest code source branch if this command you can’t use then getting error link merge or rebase.
WHAT IS GIT DIFF COMMAND?
WHAT IS GIT DIFF COMMAND? Diff command is used in git to track the difference between the changes made on a file. Diff Command will produce the changes in all the files that are present. For the changes on some specific files only, type the name of the file after the command name. 1) git diff 2) git diff filename
WHAT IS GIT DIFF COMMAND?
WHAT IS GIT DIFF COMMAND? The first line shows the file names that have been considered as the input in git diff. You can see that they have been marked by a and b along with the two different file state that has been taken as input. This line is not of use. This shows the metadata related to the command and the execution of it on the files. As you must be aware by our discussion in Dot Git folder, this is the object hash value required by Git for internal use. This line defines the symbol, called a legend, to tell you what is used to describe the first file and what is used to describe the second file. As you can see, - is used in front of the first file, and + is used in front of the second file. So whenever diff shows you the changes related to the first file, they will be marked by - and the changes in the second file will be marked by the symbol +. The fourth line shows you symbol @@ and symbols ahead of it. They are called chunks. Chunks in git diff define the change' summary. In our image below the following chunk can be seen @@ -1,2 +1 @@ This means that lines one and two were changed in the first file and line one was changed in the second file. Remember the - and + symbol used in the third point as a symbol to the first and second file respectively. 1. 2. 3. 4. 5.
WHAT IS GIT DIFF COMMAND?
DO YOU KNOW SOURCETREE??
SourceTree is a graphical user interface (GUI) desktop that allows users to simplify how they interact with Git repositories. DO YOU KNOW SOURCETREE??
SourceTree is a graphical user interface (GUI) desktop that allows users to simplify how they interact with Git repositories. Supported OS Mac OS X & Windows DO YOU KNOW SOURCETREE??
GIT HOOKS
GIT HOOKS If you want to perform custom actions when a certain event takes place in a Git repository, hooks are your tool of choice. They let you normalize commit messages, automate testing suites, notify continuous integration systems, and much more. After this article, you’ll understand the many ways in which Git hooks can streamline your workflow.
GIT HOOKS
GIT HOOKS
GIT HOOKS https://www.atlassian.com/git/tutorials/git-hooks READ MORE
GIT BISECT
The Git bisect command helps you to find bad and good commits. GIT BISECT
The Git bisect command helps you to find bad and good commits. GIT BISECT To start the git bisect git bisect start let git bisect know about a good commit git bisect good a123 let git bisect know about a bad commit git bisect bad z123
GIT BLAME
If you need to examine the content of any file line by line, you need to use git blame. It helps you to determine who made the changes to a file. GIT BLAME git blame <your_file_name>
WHAT IS ALTERNATIVE FOR GIT?
SVN (Subversion) WHAT IS ALTERNATIVE FOR GIT? Subversion exists to be universally recognized and adopted as an open-source, ... Mercurial Mercurial is dedicated to speed and efficiency with a sane user interface. It ...
Perforce WHAT IS ALTERNATIVE FOR GIT? Perforce Visibility, access control, workflow and code management for Git environments. ... Bazaar Bazaar is a version control system that helps you track project history over time and to collaborate easily with others. Other Many more...
Now what is the base git practice in live projects 01 Create Issue (As per the working on task details 02 Create MR (Merge request with add reviewer) 03 Check out branch 04 Commit and push code if single commit GITLAB (REPO.9SPL.COM) 05 After one commit use amend 06 Reviewer review code and merge MR
Now what is the base git practice in live projects 01 Create Branch from base branch. 02 Check out branch 03 Commit and push code if single commit 04 After one commit use amend GITHUB/BITBUCKET 05 Create PR (Pull request with add reviewer) 06 Reviewer review code and merge PR
Using Smart Commits JIRA/BITBUCKET
Using Smart Commits JIRA/BITBUCKET Syntax <ISSUE_KEY> #<COMMAND_1> <optional COMMAND_1_ARGUMENTS> #<COMMAND_2> <optional COMMAND_2_ARGUMENTS> ... #<COMMAND_n> <optional COMMAND_n_ARGUMENTS>
Using Smart Commits JIRA/BITBUCKET Multiple commands on a single issue <ISSUE_KEY> #<COMMAND_1> <optional COMMAND_1_ARGUMENTS> #<COMMAND_2> <optional COMMAND_2_ARGUMENTS> ... #<COMMAND_n> <optional COMMAND_n_ARGUMENTS> JRA-123 #time 2d 5h #comment Task completed ahead of schedule #resolve Example
Using Smart Commits JIRA/BITBUCKET OutPut
Using Smart Commits JIRA/BITBUCKET Multiple commands on multiple issues <ISSUE_KEY1> <ISSUE_KEY2> ... <ISSUE_KEYn> #<COMMAND_1> <optional COMMAND_1_ARGUMENTS> #<COMMAND_2> <optional COMMAND_2_ARGUMENTS> ... #<COMMAND_n> <optional COMMAND_n_ARGUMENTS> JRA-123 JRA-234 JRA-345 #resolve #time 2d 5h #comment Task completed ahead of schedule Example
https://www.9series.com/ QUESTION ANSWER
https://www.9series.com/ THANKS YOU FOR ATTENDING THIS SESSION

Git Commands Every Developer Should Know?

  • 1.
    GIT COMMANDS EVERY DEVELOPER SHOULDTO KNOW? https://www.9series.com/
  • 2.
  • 3.
    WHAT IS GIT?? Gitis free and open source software for distributed version control: tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during software development. Git means that a local clone of the project is a complete version control repository. These fully functional local repositories make it easy to work offline or remotely.
  • 4.
  • 5.
    01 Tracks history 02Free and open source 03 Creates backups 04 Branching is easier 05 Distributed development. Many More... GIT FEATURES GIT features
  • 6.
    Git Basic Git cloneis a command for downloading existing source code from a remote repository (like Github, for example). In other words, Git clone basically makes an identical copy of the latest version of a project in a repository and saves it to your computer. Git clone git clone <https://name-of-the-repository- link> Cloning a local or remote repository Cloning a bare repository Using shallow options to partially clone repositories Git URL syntax and supported protocols
  • 7.
    Git Basic git clonehttps://github.com/abc/Git-Example.git Clone with HTTPs section
  • 8.
    Git Basic git clonehttps://github.com/abc/Git-Example.git git clone <repo> <directory> Clone with HTTPs section Cloning to a specific folder
  • 9.
    Git Basic git clonehttps://github.com/abc/Git-Example.git git clone <repo> <directory> git clone --branch <tag> <repo> Clone with HTTPs section Cloning to a specific folder Cloning a specific tag
  • 10.
    Git Basic git clone-branch new_feature git://remoterepository.git git clone -branch
  • 11.
    Git Basic git clone-branch new_feature git://remoterepository.git git clone <repogit clone --template= <template_directory> <repo location> <directory> git clone -branch git clone --template
  • 12.
    Git Basic git clone-branch new_feature git://remoterepository.git git clone <repogit clone --template= <template_directory> <repo location> <directory> git clone https://username@github.com/username/repository.git git clone -branch git clone --template git clone git@remote.git git clone https://username:password@github.com/username/repository.git
  • 13.
  • 14.
    Git Basic git clone https://<token>@github.com/<username>/<repository>.git Clonethe Repo token Other many why to you can clone your git projects.
  • 15.
  • 16.
    HOME Clone multiple gitrepositories in one local directory? WORK One questions
  • 17.
    GitHub Cloud Providers Git GitHub Onpremises Bitbucket GitLab Cloud GitLab On premises Azure DevOps Git Atlassian Stash (old version of Bibucket Server) Other many providers is available in market.
  • 18.
    GIT CONFIG git configuser.name "Hitesh" git set username and email git config user.email "abc@gm.co" git config credential.helper store Note : You need to store global git config then you can use bllow command. git config --global user.name / user.email
  • 19.
    GIT BASIC COMMANDS Gitclone git clone is primarily used to point to an existing repo and make a clone or copy of that repo at in a new directory,
  • 20.
    GIT BASIC COMMANDS Gitbranch The git branch command lets you create, list, rename, and delete branches
  • 21.
    GIT BASIC COMMANDS Creatinga new branch commit and push: git branch <branch-name> git status git add README.md git add --all git commit -m "Editing the README to try out git add/commit"
  • 22.
    GIT BASIC COMMANDS Shortstatus flags are: ?? - Untracked files A - Files added to stage M - Modified files D - Deleted files R - Renamed C - Copied U - Updated but unmerged F - Force Push.
 Other many short flags Short status flags are:
  • 23.
    GIT BASIC COMMANDS Creatinga new branch commit and push: git commit git push -u <remote> <branch-name>
  • 24.
    GIT BASIC COMMANDS Viewingbranches: git branch or git branch --list
  • 25.
    GIT BASIC COMMANDS Deletinga branch: git branch -d <branch-name>
  • 26.
    GIT BASIC COMMANDS Gitcheckout git checkout <name-of-your-branch>
  • 27.
    GIT BASIC COMMANDS GitPull git pull <remote>
  • 28.
    GIT BASIC COMMANDS Gitrevert A safer way that we can undo our commits is by using git revert. git revert 3321844
  • 29.
    GIT BASIC COMMANDS Gitmerge First you should switch to the dev branch: git checkout dev Before merging, you should update your local dev branch: git fetch
  • 30.
    GIT ADVANCE COMMANDS gitstash This Git command temporarily stores your modified files. You can work in stashed with the following Git command. git stash Usage And you can view all of your stashes with the following command git stash list And if you need a apply a stash to a branch, simply use apply git stash apply
  • 31.
    GIT ADVANCE COMMANDS gitrebase Git rebase similar to the git merge command. It integrates two branches into a single branch with one exception. A git rebase command rewrites the commit history.
  • 32.
    GIT ADVANCE COMMANDS gitrebase Git rebase similar to the git merge command. It integrates two branches into a single branch with one exception. A git rebase command rewrites the commit history. Usage You should use the Git rebase command when you have multiple private branches to consolidate into a single branch. And it will make the commit history linear. git rebase <base>
  • 33.
    GIT ADVANCE COMMANDS gitcherry-pick Git cherry-pick is a helpful command. It's a robust command and allows you to pick any commit from any branch and apply it to any other branch. Usage git cherry-pick <commit-hash> Git cherry-pick doesn’t modify the history of a repository; instead, it adds to the history.
  • 34.
    GIT ADVANCE COMMANDS gitarchive Git archive command will combine multiple files into a single file. It's like a zip utility, so it means you can extract the archive files to get individual files. Usage git archive --format zip HEAD > archive-HEAD.zip It will create a zip archive of the current revision.
  • 35.
    GIT ADVANCE COMMANDS Rewritinghistory change with amend Git commit --amend and other methods of rewriting history Changing the Last Commit: git commit --amend git commit --amend -m "an updated commit message" git push -f —> It’s use to this is latest code source branch if this command you can’t use then getting error link merge or rebase.
  • 36.
    GIT ADVANCE COMMANDS Gittracks changes git reset --hard git reset --hard <SOME-COMMIT> The “--hard” option is used in order to reset the files of the index (or the staging area) and of the working directory. -- hard which will completely destroy any changes and remove them from the local directory.
  • 37.
    GIT ADVANCE COMMANDS Gittracks changes git reset --soft HEAD@{1} which will keep your files, and stage all changes back automatically. git reset --mixed HEAD@{1} which is the default, and keeps all files the same but unstages the changes. This is the most flexible option, but despite the name, it doesn’t modify files. git commit -m "Reverting to the state of the project at f414f31" git push -f —> It’s use to this is latest code source branch if this command you can’t use then getting error link merge or rebase.
  • 38.
    WHAT IS GITDIFF COMMAND?
  • 39.
    WHAT IS GITDIFF COMMAND? Diff command is used in git to track the difference between the changes made on a file. Diff Command will produce the changes in all the files that are present. For the changes on some specific files only, type the name of the file after the command name. 1) git diff 2) git diff filename
  • 40.
    WHAT IS GITDIFF COMMAND?
  • 41.
    WHAT IS GITDIFF COMMAND? The first line shows the file names that have been considered as the input in git diff. You can see that they have been marked by a and b along with the two different file state that has been taken as input. This line is not of use. This shows the metadata related to the command and the execution of it on the files. As you must be aware by our discussion in Dot Git folder, this is the object hash value required by Git for internal use. This line defines the symbol, called a legend, to tell you what is used to describe the first file and what is used to describe the second file. As you can see, - is used in front of the first file, and + is used in front of the second file. So whenever diff shows you the changes related to the first file, they will be marked by - and the changes in the second file will be marked by the symbol +. The fourth line shows you symbol @@ and symbols ahead of it. They are called chunks. Chunks in git diff define the change' summary. In our image below the following chunk can be seen @@ -1,2 +1 @@ This means that lines one and two were changed in the first file and line one was changed in the second file. Remember the - and + symbol used in the third point as a symbol to the first and second file respectively. 1. 2. 3. 4. 5.
  • 42.
    WHAT IS GITDIFF COMMAND?
  • 43.
  • 44.
    SourceTree is agraphical user interface (GUI) desktop that allows users to simplify how they interact with Git repositories. DO YOU KNOW SOURCETREE??
  • 45.
    SourceTree is agraphical user interface (GUI) desktop that allows users to simplify how they interact with Git repositories. Supported OS Mac OS X & Windows DO YOU KNOW SOURCETREE??
  • 46.
  • 47.
    GIT HOOKS If youwant to perform custom actions when a certain event takes place in a Git repository, hooks are your tool of choice. They let you normalize commit messages, automate testing suites, notify continuous integration systems, and much more. After this article, you’ll understand the many ways in which Git hooks can streamline your workflow.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
    The Git bisectcommand helps you to find bad and good commits. GIT BISECT
  • 53.
    The Git bisectcommand helps you to find bad and good commits. GIT BISECT To start the git bisect git bisect start let git bisect know about a good commit git bisect good a123 let git bisect know about a bad commit git bisect bad z123
  • 54.
  • 55.
    If you needto examine the content of any file line by line, you need to use git blame. It helps you to determine who made the changes to a file. GIT BLAME git blame <your_file_name>
  • 56.
  • 57.
    SVN (Subversion) WHAT ISALTERNATIVE FOR GIT? Subversion exists to be universally recognized and adopted as an open-source, ... Mercurial Mercurial is dedicated to speed and efficiency with a sane user interface. It ...
  • 58.
    Perforce WHAT IS ALTERNATIVEFOR GIT? Perforce Visibility, access control, workflow and code management for Git environments. ... Bazaar Bazaar is a version control system that helps you track project history over time and to collaborate easily with others. Other Many more...
  • 59.
    Now what isthe base git practice in live projects 01 Create Issue (As per the working on task details 02 Create MR (Merge request with add reviewer) 03 Check out branch 04 Commit and push code if single commit GITLAB (REPO.9SPL.COM) 05 After one commit use amend 06 Reviewer review code and merge MR
  • 60.
    Now what isthe base git practice in live projects 01 Create Branch from base branch. 02 Check out branch 03 Commit and push code if single commit 04 After one commit use amend GITHUB/BITBUCKET 05 Create PR (Pull request with add reviewer) 06 Reviewer review code and merge PR
  • 61.
  • 62.
    Using Smart Commits JIRA/BITBUCKET Syntax <ISSUE_KEY>#<COMMAND_1> <optional COMMAND_1_ARGUMENTS> #<COMMAND_2> <optional COMMAND_2_ARGUMENTS> ... #<COMMAND_n> <optional COMMAND_n_ARGUMENTS>
  • 63.
    Using Smart Commits JIRA/BITBUCKET Multiplecommands on a single issue <ISSUE_KEY> #<COMMAND_1> <optional COMMAND_1_ARGUMENTS> #<COMMAND_2> <optional COMMAND_2_ARGUMENTS> ... #<COMMAND_n> <optional COMMAND_n_ARGUMENTS> JRA-123 #time 2d 5h #comment Task completed ahead of schedule #resolve Example
  • 64.
  • 65.
    Using Smart Commits JIRA/BITBUCKET Multiplecommands on multiple issues <ISSUE_KEY1> <ISSUE_KEY2> ... <ISSUE_KEYn> #<COMMAND_1> <optional COMMAND_1_ARGUMENTS> #<COMMAND_2> <optional COMMAND_2_ARGUMENTS> ... #<COMMAND_n> <optional COMMAND_n_ARGUMENTS> JRA-123 JRA-234 JRA-345 #resolve #time 2d 5h #comment Task completed ahead of schedule Example
  • 66.
  • 67.