DevOps Classsroom Series – 07/Feb/2021
Git Contd..
Scenario: Understanding Branches
- There will be many cases where parallel tracks of development will happpen on your projects
- Git branches enable you to create parallel tracks of development. In Git there is already a default branch which is referred as master
- Now lets create two more branches
- rel_1.0
- rel_1.1
- rel_1.0
- Now lets make a change in rel_1.0 and commit the changes to local repo
- Now lets make a change in rel_1.1 and commit the changes to local repo
- Branch will point to the latest commit on that branch and head will be pointing towards branch which points to latest commit
- Now we need changes of rel_1.0 branch to be in master.
- Fast forward merge
- Fast forward merge
- Lets make changes in master branch and commit those changes and also do some changes on rel_1.0 branch
- Now we need to merge the changes from rel_1.0 to master
- Merges might lead to conflicts and that needs to be resolved
- Merges might lead to conflicts and that needs to be resolved
- Git Rebase
- Refer Here for documenation
- Lets rebase master onto rel_1.1
git checkout rel_1.1 git rebase master # fix merge conflicts # add the changes usign git add # then continue the rebase git rebase --continue
- In git if you want to pick certain commits and add it to the branch then that is referred as cherry-picking
- Now lets create two branches from master
- rel_1.2
- rel_1.3
- Refer Here for cherry-pick documentation
- Now we have understood three ways bringing changes from one branch to other
- merge
- rebase
- cherry-pick
How Git Works
- To understand how git works, we need to know about
- Hashing (SHA1):
- This is transformation of string of characters into a shorted fixed length value
- Two text with same value will have same hash
- Hashing (SHA1):
- Git can be reffered as a stupid content tracker.
- In Git every commit id is generated by calculating hash of
- Changes
- Author
- Date time
- Message
- Every commit will have a parent commit
- In Git Commit tree stands for folder and binary large object (blob) stands for file
Fourth Area of git
- Fourth area of git is referred as remote repository, which is used to collobarate work done by multiple developers in an orginization
- Git remote repository contains the same .git folder and in addition to that it will have
- connectivity options (for developers to connect)
- To have this on git remote repository some daemon will be running.
- There are many ways to configure git remote repository
- We can host git remote repository on some shared folder in your organization
- We can use some git remote repository softwares
- Gitolite
- GitLab
- We can use some hosted git remote repository options
- GitHub
- BitBucket Cloud
- GitLab
- Azure Source repos
- AWS Code Commit
- We can have a local repository which is connected to multiple remote repositories
- Just like master was a default branch, the default remote repository also will have a name origin
- So now lets create a new repository in GitHub and send all the changes which we have done in the class to that repository
- Add remote repository to local repo
- Sending the changes from local repo to remote repo is referred as push and the command for pushing is
git push <name-of-remote> <name-of-branch>
- Lets try to push all the branches to remote repo
- Add remote repository to local repo
- How to get the copy of the code from existing remote repository
- This operation is referred as clone.
- Now lets checkout to rel_1.1
- This operation is referred as clone.
- To push the changes to remote repository, we need permissions
Next Steps
- Understanding multiple users workflow
- Understanding recieving latest changes from remote repository
- Understanding git tags
- How to make changes to the existing commits