Branching: Overview
● Software Branching is a technique used to achieve code isolation.
◆ Release Branches: Used to create a snapshot of the codebase at time of release. To ensure stability and minimize risk, only severe bug fixes are permitted in release branches.
◆ Development Branches: Used to isolate ongoing development from one another. Often different projects make changes to the same area of code. Creating development branches ensure isolation from one another
● Avoid making branch blobs !!! Continuous Integration !!!
Branching: Overview
● Git's branching is EXTREMELY lightweight and fast.
● GitHub's Merge Request feature makes integration easy. You rarely need to merge manually ( GitHub will do it). But it is shown in upcoming slides for completeness.
1. Push your development branch to server (e.g. GitHub)
2. Point your browser to https://github/
Request by specifying which branches you want to merge from and to.
● The following will show you how to create, switch, push, and delete branches. Once you're in a branch, you would then commit files like before.
● Nearly all of the commands mentioned already will be scoped to your current branch
Branching: Listing Branches
● Command: git branch [-a/--all]
● This command lists all local and remote branches
● Asterisk indicates which branch you're currently on
● The remotes/origin branches indicate branches residing on the remote server
[anandg anandg@ /home/anandg/testrepo (master)]$ git branch
* master
[anandg anandg@ /home/anandg/testrepo (master)]$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/Internal
remotes/origin/python2
remotes/origin/master
remotes/origin/prototype
remotes/origin/releasecandidate
remotes/origin/python3
Branching: Creating a Branch
● Command: git branch
● This command creates a branch in your local repository
● Note: The parent branch is based on where you run this command. You can run git checkout
[anandg anandg@ /home/anandg/testrepo (master)]$ git branch anandg-temp
[anandg anandg@ /home/anandg/testrepo (master)]$ git branch -a
anandg-temp
* master
remotes/origin/HEAD -> origin/master
remotes/origin/Internal
remotes/origin/python2
remotes/origin/master
remotes/origin/prototype
remotes/origin/releasecandidate
remotes/origin/python3
Branching: Switching to a Branch
● Command: git checkout
● This command switches to the specified branch.
● More specifically, it alters your current working directory to a particular set of snapshots in time.
[anandg anandg@ /home/anandg/testrepo (master)]$ git branch anandg-temp
[anandg anandg@ /home/anandg/testrepo (master)]$ git branch
anandg-temp
* master
[anandg anandg@ /home/anandg/testrepo (master)]$ git checkout anandg-temp
[anandg anandg@ /home/anandg/testrepo (master)]$ git branch
* anandg-temp
master
Branching: Merging Branches
● Command: git merge
● This command merges
● Merging can be a totally local operation. You can merge-in another local branch or even a remote tracking branch.
● We talked about git push and git pull previously. But let's take a closer look as to what this means.
[anandg anandg@ ~/home/anandg/testrepo2 (master)]$ git merge foo
# Here, you are merging the local branch 'foo' into your current branch
[anandg anandg@ ~/home/anandg/testrepo2 (master)]$ git merge origin/bar
# Here, you are merging the remote tracking branch 'bar' into your current branch. But this is a completely LOCAL operation !!!
Branching: Merge Conflicts
● When merging or pulling, you may observe a merge conflict error.
● To resolve, open the conflicted file with your favorite editor.
Find and resolve all, <<<, ===, and >>> sections.
[anandg@ ~/home/anandg/testrepo2 (master)]$ git pull
remote: Counting objects: 178, done.
remote: Compressing objects: 100% (114/114), done.
remote: Total 178 (delta 87), reused 150 (delta 64)
Receiving objects: 100% (178/178), 68.26 KiB, done.
Resolving deltas: 100% (87/87), done.
From github:testrepo2
3b06595..60c4184 master -> origin/master
* [new branch] anand-temp2 -> origin/anand-temp2
Auto-merging file5.py
CONFLICT (content): Merge conflict in file5.py
Automatic merge failed; fix conflicts and then commit the result.
[anandg@ ~/home/anandg/testrepo2/ (master|MERGING)]$
● git status will also show "unmerged paths"
[anandg@ ~/home/anandg/testrepo2 (master|MERGING)]$ git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 1 and 30 different commits each, respectively.
# (use "git pull" to merge the remote branch into yours)
#
# You have unmerged paths.
# (fix conflicts and run "git commit")
#
# Changes to be committed:
#
# modified: file2.py
# modified: file3.py
# modified: file4.py
# new file: file6.py
#
# Unmerged paths:
# (use "git add
#
# both modified: file5.py
#
[anandg@ ~/home/anandg/testrepo2 (master|MERGING)]$
● Search for HEAD in the file and edit to keep what you want.
● You will need to delete the <<< HEAD, ===, and >>> lines as well.
● When done, save the file...add the file...commit the file .
<<<<<<< HEAD
var1 = 0
dict1 = {}
=======
newStr = 'test string'
>>>>>>> 60c418499e3a272d470035d0f8956e9e1fb1253e
Branching: Closer Look
● Remote Repository (aka Remote):
The source of the local repository from where it was cloned from.
Remotes are generally referred to via an alias like origin.
Interaction with the remote is done via git clone, git push, and git fetch.
● Local Branches:
Set of local branches that are available for the user to work out of.
● Remote Tracking Branches:
Despite the name, these branches reside on the LOCAL
CLIENT !!! They provide a tracking mechanism between the remote's
branches and your local branches (e.g. a buffer if you will)
Branching: Deleting a Branch
● Command: git branch -d/-D
● This command merges deletes the branch
● The -D is the big hammer that doesn't require content to be merged.
[anandg anandg@ /home/anandg/testrepo2 (master)]$ git branch anandg-ipv6-fix
[anandg anandg@ /home/anandg/testrepo2 (master)]$ git branch
anandg-ipv6-fix
* master
[anandg anandg@ /home/anandg/testrepo2 (master)]$ git branch -d anandg-ipv6-fix
[anandg anandg@ /home/anandg/testrepo2 (master)]$ git branch
* master
Branching: Deleting a Branch on a Remote
● Command: git push
● This command merges deletes the branch
remote server (e.g. origin).
[anandg anandg@ /home/anandg/testrepo2 (master)]$ git branch -a
foo
* master
remotes/origin/HEAD -> origin/master
remotes/origin/foo
remotes/origin/master
[anandg anandg@ /home/anandg/testrepo2 (master)]$ git push origin :foo
To github:testrepo2.git
- [deleted] foo
[anandg anandg@ /home/anandg/testrepo2 (master)]$ git branch -d foo
Deleted branch foo (was adbed2d).
JTG Marriott Hotel and Casino - Travel Weekly
ReplyDeleteJTG Marriott Hotel 포천 출장샵 and Casino offers accommodation at affordable rates. Click 의왕 출장마사지 to 안산 출장샵 enjoy 인천광역 출장안마 our Hotel 청주 출장샵 Search page. Save up to 70% off with our hotel rewards