======================Branch merging types===================
1.Fast forward merge:
2.3 way merge
git log --all --graph
shiva@DESKTOP-4B0O632 MINGW64 /d/Cloud-DevOps/GIT (master)
$ git branch feature1
shiva@DESKTOP-4B0O632 MINGW64 /d/Cloud-DevOps/GIT (master)
$ git log --all --graph
* commit 8b1208132b964f45a1a0a80a8eddab7708d24363 (HEAD -> master, feature1)
| Author: shivasingam111 <shivasingam111@gmail.com>
| Date: Wed Dec 20 13:52:09 2023 +0530
|
| test file2
|
* commit 82bc1d1f09aac796bc324d8736d02b2b20dc62f1
| Author: shivasingam111 <shivasingam111@gmail.com>
| Date: Wed Dec 20 13:44:22 2023 +0530
|
| pushing repo first commit
|
* commit 7b9fe8f6b2ae057d9ad5660c147722fbb5df6c1e
| Author: shivasingam111 <shivasingam111@gmail.com>
| Date: Wed Dec 20 13:43:24 2023 +0530
|
| pushing repo first commit
|
* commit cae3477dfbd3400060038d58cdbd75fa929a5b7c
Author: shivasingam111 <shivasingam111@gmail.com>
Date: Wed Dec 20 13:17:28 2023 +0530
first file change
--------------------------------------------------------------------------------------------------------------
git checkout feature1
now if we see head will point to the feature branch
git log --all --graph
* commit 8b1208132b964f45a1a0a80a8eddab7708d24363 (HEAD -> feature1, master)
now in feature branch edit any file with some info
now git add . & git commit -m "pushing some data from feature branch"
It will be like below
Now go to the master branch make some changes & do
git add . & git commit -m "pushing some data from master branch"
git branch conflict
i.e whenever merge conflicts will come sit with team & resolve the merge conflict with right changes then push the code into master.
========== Fast Forward Merge Vs Recursive Three Way Merge ====================
Branch will copied only commits not code to be copy
branch will be created only from exiting branches
*Head determines you which branch you are
Fastforward --> create a branch from master and the childbranch is feature1 and make somechanges note this process called as liner changes and checkout to master branch then git merge feature1 branch
then all commits from feature1 branch will transffer to master branch its called as the fast forward merge
ref: https://www.atlassian.com/git/tutorials/using-branches/git-merge
it will make the master branch always look at the latest commit id.
Note: in this process we don't need to make any code changes in master branch
In recursive 3 way change when we made changes in both feature1 branch along with master branch
In this process to match the changes in diff branches commit git will create a new commitid dynamically & it will merge the code
clone a branch and create
git branch newclonebranch feature1branch
==================git fetch and pull , push=============
Ref : https://www.atlassian.com/git/tutorials/syncing/git-fetch
The git fetch command downloads commits, files, and refs from a remote repository into your local repo. Fetching is what you do when you want to see what everybody else has been working on. It’s similar to svn update in that it lets you see how the central history has progressed, but it doesn’t force you to actually merge the changes into your repository. Git isolates fetched content from existing local content; it has absolutely no effect on your local development work. Fetched content has to be explicitly checked out using the git checkout command. This makes fetching a safe way to review commits before integrating them with your local repository.
When downloading content from a remote repo, git pull and git fetch commands are available to accomplish the task. You can consider git fetch the 'safe' version of the two commands. It will download the remote content but not update your local repo's working state, leaving your current work intact. git pull is the more aggressive alternative; it will download the remote content for the active local branch and immediately execute git merge to create a merge commit for the new remote content. If you have pending changes in progress this will cause conflicts and kick-off the merge conflict resolution flow.
By default git storage in remote place in github we called as origin
$ git remote -v
origin https://github.com/shivscloud/git-professional.git (fetch)
origin https://github.com/shivscloud/git-professional.git (push)
git branch -a
conflict
* feature1 (local branch)
master (local)
remotes/origin/feature1 (remote branch)
remotes/origin/master (remote branch)
to view the branch where its targeting
$ git branch -vv
conflict b464cf9 finishing some data from faeture branch
* feature1 85af2cf [origin/feature1] finishing some data from faeture branch
master 217f0f0 [origin/master] from master branch pushing code
here local branches are tracking to remote branches
=============to view origin url============
$ git remote show origin
* remote origin
Fetch URL: https://github.com/shivscloud/git-professional.git
Push URL: https://github.com/shivscloud/git-professional.git
HEAD branch: master
Remote branches:
feature1 tracked
master tracked
Local branches configured for 'git pull':
feature1 merges with remote feature1
master merges with remote master
Local refs configured for 'git push':
feature1 pushes to feature1 (local out of date)
master pushes to master (local out of date)
$ git fetch
remote: Enumerating objects: 2, done.
remote: Counting objects: 100% (2/2), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (2/2), 1.20 KiB | 153.00 KiB/s, done.
From https://github.com/shivscloud/git-professional
85af2cf..3e38296 feature1 -> origin/feature1
217f0f0..47331df master -> origin/master
Git Pull : it merges remote branch into the local branch (for this git fetch will run background)
============Advanced git topoics=================
https://www.youtube.com/watch?v=Uszj_k0DGsg
https://www.youtube.com/watch?v=qsTthZi23VE
0 Comments