GIT repository(mod 10)
GIT repository(mod 10)
Repository, Branching,
and Merging
AN INTRODUCTION TO GIT COMMANDS(MODULE 10)
Introduction
•Git(“Global information tracker”) is a tool used to track changes in files, especially
in code.
•It helps developers work together and manage versions of their projects easily.
Initializing a Repository
•Use git init to start a Git repository in your project.
•Example: Open a terminal and type git init.
Understanding Branches
A branch is like a copy of your project where you can work on changes without affecting
the main project.
•The main branch (called main or master) is the default and contains the final, stable version
of your project.
•You can create other branches to test new features or fixes, and later combine them into the
main branch.
This saves time because you don’t have to run two separate commands (git branch
and git checkout)
Merging Branches
•Use git merge branch_name to combine changes from one branch into another.
When resolving a merge conflict between two files, you need to add the file(s) you have
fixed using git add.
So, if the conflict is in File1 and File2, after manually resolving the conflict in each file:
1.Use git add File1 to mark File1 as fixed.
2.Use git add File2 to mark File2 as fixed.
Once all conflicted files are added, use git commit to finalize the merge.
Best Practices
•Commit your work often with clear messages.
•Pull updates from the main branch before merging to avoid conflicts.
•Learning to use commands like branching and merging makes coding more efficient.