Lab Files on github.com at: https://github.com/vjpudelski/cc_gitmergeresetsbranches
This presentation focuses on the collaboration of multiple developers on the same codebase through merging, resets and branches. Merging allows for developers to join their code with the latest point of code in the common codebase. Resets are just one of the ways to undo or reset changes that have occurred that need to either be reviewed more before being committed or in some cases undone completely. Branching allows developers to isolate their efforts in the codebase and experiment without fear of breaking the release branch of the codebase. All of these together are essential for developers to work together as a team on the same codebase.
2. Victor J. Pudelski
V. P. of Solutions @ TSC, LLC
Founder/Developer @ Next Link Software, LLC
Developer ~20 yrs
Worked mostly in ECM
(boring stuff)
Started working in git in
2010-ish
Created repos at 4
companies
Was git expert for TSG
3. Git Merge, Resets and
Braches
Two developers can work on the same files at the same time and it
doesn't have to be scary. Git Merge makes it easy to ensure we can see
what's changed, where conflicts occurred and give us an opportunity to
resolve them peacefully. In general, Git provides tools for rolling files
back, isolating R&D initiatives and much much more. This session will
focus on some more advanced Git commands and how we can use them
in our daily projects to ensure source control is never a burden but an ally
in getting work done quickly, easily and without interrupting other fellow
developers.
4. Agenda
• GIT Merges and why they aren’t so bad
• Rolling Back mistakes
• Isolating our development
5. Disclaimer
• Many of the Images are from atlassian.com the creators or
bitbucket. They write some great documentation, check it out
sometime…
• Things here are greatly simplified but can be applied to the
most complex of solutions and teams…
• This is not an all encompassing course. There are so many
resources to use. Find what works for you…
6. Git Merge is
• Scary Monster
• Very Difficult to recover from
• Takes a PHD in Comp Sci to
understand
10. Git Merge is
• A natural part of development
• Easy to identify what
happened
• Can be quick to resolve when
conflict arises
• NOT SCARY!!!
11. How do you know you need to
merge?
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/vjpudelski/GitMergePractice.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
12. <<<<<<< HEAD
Program prog = new Program();
prog.CreateMenu();
}
public void CreateMenu(){
Console.WriteLine("Title of Application");
Console.WriteLine();
Console.WriteLine("1 - Search");
Console.WriteLine("2 - Add New");
Console.WriteLine("3 - Delete Item");
=======
Console.WriteLine("GoodBye!");
for (int i = 0; i < 10; i++){
Console.Write("i ");
}
>>>>>>> d45ccef3a008e0ebfd1766b6d8fb0e77eb77d88f
13. <<<<<<< HEAD
Program prog = new Program();
prog.CreateMenu();
}
public void CreateMenu(){
Console.WriteLine("Title of Application");
Console.WriteLine();
Console.WriteLine("1 - Search");
Console.WriteLine("2 - Add New");
Console.WriteLine("3 - Delete Item");
=======
These are the changes
you have made…
15. <<<<<<< HEAD
Program prog = new Program();
prog.CreateMenu();
}
public void CreateMenu(){
Console.WriteLine("Title of Application");
Console.WriteLine();
Console.WriteLine("1 - Search");
Console.WriteLine("2 - Add New");
Console.WriteLine("3 - Delete Item");
=======
Console.WriteLine("GoodBye!");
for (int i = 0; i < 10; i++){
Console.Write("i ");
}
>>>>>>> d45ccef3a008e0ebfd1766b6d8fb0e77eb77d88f
16. Merge creates a commit
• You are saving changes required to combine your code
and other code
• This is why in times of conflict you need to commit again
to complete merge
19. What if I Mess Up?
• I have created a commit and it is WRONG!
• I don’t need the change
• I need to return to another commit
git reset --hard
20. “--hard”
• Hard sounds while, hard?
• There is also —mixed and —soft
• Hard - lose changes, totally undone
• Mixed - changes in stage reset to working directory but
nothing lost
• Soft - reset to commit, modified files set to staged (add)
21. • I accidentally staged a change I shouldn’t have? (MIXED)
• I committed something I shouldn’t have and I want the
change? (SOFT)
• I need to blow away changes? (HARD)
29. GIT Merge & Branches
• You need to be on the destination branch
• You merge into a branch
git merge <<branch>>
• Sometimes you will not have conflict and it will just work
and That’s All Folks!
30. Recap
• Git Merge is not that scary at all
• If we mess up, we have options
• Can always save our work to separate branches