DevOps Series: An Expert Guide On Advanced GitHub

Advanced GitHub

Previous Blog: DevOps Series
----------------------------------------------

Git Continued:-
 

1. To Create branch
 

      a. git checkout branch_name
      b. git checkout -b new_branch_name ⇒ create and checkout to the newly created branch
      c. Example
         Checkout to master branch and create 2 branches stage and dev from that with command following :
         git checkout master ⇒ This will checkout to master branch.
         git checkout -b stage ⇒  This will create stage branch from master.
         git checkout -b dev ⇒ This will create dev branch from master.
      d. Add/Commit changes in the branches
 

2. Merge branches
 

      a. git checkout to branch in which you want changes to be merged
          git checkout stage
      b. git merge dev ⇒ This command will merge all changes of dev branch into the stage
      c. If you find any conflicts, then you need to solve that by removing the following lines:
          <<<HEAD and >>>commit 
          And keep only those changes which need to be pushed on the repo. And remove all unnecessary changes.
      d. Commit those changes and push it to the repo

3. Rebase Branches
 

      a. Create a feature branch from master/any branch
      b. Make changes and push them to feature branch
      c. To add changes of feature branch into master, follow this steps,
            - git checkout master (in which changes need to be merged)
            - git rebase feature_branch (Branch from which changes to be taken) Non-interactive
              git rebase feature_branch --interactive (Rebase changes in an interactive way.) Where one can pick and drop commits while merging code into the repo
            - Keep adding changes from commits and at you need to take pull once again and solve conflicts
            - After solving all conflicts, merge and push them to the repo

4. See History

     a. To see the ENTIRE history of the repo in a graphical manner the following command can be used:
          - “git log --graph --oneline --decorate --all”
     b. To see the history of a particular branch in the repo in a graphical manner the following command can be used:
          - “git log --graph --oneline --decorate”

5. Git Stashing

     a. To change the branch while working and not to commit half work done to use the following command:
          - Git stash
     b. To see which stashes you’ve stored, you can use:
          - git stash list
     c. You can reapply the one you just stashed by using the command shown in the help output of the original stash command:
          - git stash apply
     d. If you want to apply one of the older stashes, you can specify it by naming it, like this:
          - git stash apply stash@{2}
     e. The changes to your files were reapplied, but the file you staged before wasn’t restaged. To do that, you must run the git stash apply command with a --index option to tell the command to try to reapply the staged changes:
          - git stash apply --index
     f. The apply option only tries to apply for the stashed work — you continue to have it on your stack. To remove it, you can run the following command with the name of the stash to remove:
          - Git stash drop
     g. To apply the stash and then immediately drop it from your stack use:
          - Git stash pop

6. Git cherry-pick

     a. Git cherry-pick is used for merging specific commit into the specific branch

         Commands:-
          - git reflog  ⇒ to get commit id
          - git cherry-pick commit_id commit_id
          - git push origin branch_name ⇒ to push changes on the branch

I hope this blog helps you to expand your GitHub knowledge …Thanks! If you need more assistance regarding DevOps Services, feel free to contact us now.

--------------------------------------
Next BlogDevOps Series