Git Branching:
Use a branch to isolate development work without affecting other branches in the repository. Each repository has one default branch, and can have multiple other branches. You can merge a branch into another branch using a pull request.
Branches allow you to develop features, fix bugs, or safely experiment with new ideas in a contained area of your repository.
Git Revert and Reset:
Two commonly used tools that git users will encounter are those of git reset and git revert . The benefit of both of these commands is that you can use them to remove or edit changes you’ve made in the code in previous commits.
Git Rebase and Merge:
What Is Git Rebase?
Git rebase is a command that lets users integrate changes from one branch to another, and the logs are modified once the action is complete. Git rebase was developed to overcome merging’s shortcomings, specifically regarding logs.
What Is Git Merge?
Git merge is a command that allows developers to merge Git branches while the logs of commits on branches remain intact.
The merge wording can be confusing because we have two methods of merging branches, and one of those ways is actually called “merge,” even though both procedures do essentially the same thing.
What’s the Difference Between Merge and Rebase?
The main difference between git merge and git rebase is that git merge is a way of combining changes from one branch (source branch) into another branch (target branch) where as git rebase is a way of moving the changes from one branch onto another branch.
What’s the Difference Git Stash,Cherry-pick and Resolving Conflicts?
Git Stash:
Git stash is a command that allows you to temporarily save changes you have made in your working directory, without committing them. This is useful when you need to switch to a different branch to work on something else, but you don't want to commit the changes you've made in your c
urrent branch yet.
To use Git stash, you first create a new branch and make some changes to it. Then you can use the command git stash to save those changes. This will remove the changes from your working directory and record them in a new stash. You can apply these changes later. git stash list command shows the list of stashed changes.
Cherry-pick:
Git cherry-pick is a command that allows you to select specific commits from one branch and apply them to another. This can be useful when you want to selectively apply changes that were made in one branch to another.
Resolving Conflicts:
Conflicts can occur when you merge or rebase branches that have diverged, and you need to manually resolve the conflicts before git can proceed with the merge/rebase. git status command shows the files that have conflicts, git diff command shows the difference between the conflicting versions and git add command is used to add the resolved files.
Tasks:
Task1:
Add a text file called version01.txt inside the Devops/Git/ with “This is first feature of our application” written inside. This should be in a branch coming from master
After that I will create Next Branch that is Dev
-b is a branch that is, If we create a brach as a child so the perent is master, so we can use -b. when I type this command git checkout -b Dev that is, they create the new branch as same file also available to master branch.
So if you want to check which branch you are using currently, Then you type the git branch
then you see, I am in Dev branch, So you also see same file are available in master branch, That is also same file available in Dev branch, Why It is possible beacuse we use -b.
After that we open vi version01.txt editor and type some line. and save the file, After that we pull the file to remote repo.
No we create many file in Dev branch (Python.py, Java.py Bug.py , File1.py,File2.py,Bug1.py,Fiel3.py)
First we create Python.py File(bf0388e)
Now we create Java.py File.(bf0388e)
Now we create Bug.py(17cabde)
Now we create File1.py(17cabde)
Now we create File2.py(89b8383)
Now we create Bug1.py(80a051e)
Now we create Fiel3.py(1f728c7)
Now show all the commit using oneline
Now we have commit to wrong for this ID 17cabde. ,If We have commit to wrong, we can not do anything but, If you are in company this ID you commit to wrong so that is the way your manager fire you. But you think that if I revert this ID we have to safe. see
So you see when I type the command revert the file is delete but you are not safe again. when your manager come to the office and login the account,They see you have do some changes and you use revert command. See
HEAD is point to Dev and it is so, you have done revert. Now your are not safe. Now your manager fire you.
So we have second way, We can not do this way in the comany because you know manager, If your manager notice that your manager will fire you immediately. But I will show you command that is reset, If you type this command so you go to one step back let see, we commit to wrong 80a051e this file ID and you reset the file Id so you run the command one step back like 89b8383 this file ID, I will show you in terminal.
No you see when I run the command reset then
file is delete but you see 1f728c7 This ID also deleted so if your manage come to the office and they see all the file after 80a051e deleted that is the problem. Client will kill you. your manager have a no chance to safe you. Your manager immediately fire you, So please be carefull in the company.
Task2:
Difference between Marge and rebase command?
Git Merge Command:Creates a new commit that combines changes from different branches.Maintains a linear history with a merge commit, showing the branch divergence.Use when preserving the branch history is important or when working in a shared repository.
Git Rebase Command:Transplants the entire branch onto another base, rewriting commit history.Produces a cleaner, linear history without additional merge commits.Use when you want a cleaner history for your feature branch before merging into the main branch.
Task3:
Stash,Cherry-pick Command:
Git Stash Command:git stash is used to temporarily store changes that are not ready to be committed, allowing you to switch branches or perform other operations without committing incomplete work.It saves changes in the working directory and the index, but not in the commit history.After stashing changes, you can apply them later with git stash apply
or git stash pop
.
Git Cherry-pick Command:It cherry-pick` is used to apply a specific commit from one branch to another.It copies the changes introduced by the selected commit onto the current branch.Useful for applying specific changes or fixes from one branch to another without merging entire branches.
git cherry-pick <commit-hash>
Now we have completed Basic to Advance git and github, Next blog we will start to Python.