0% found this document useful (0 votes)
18 views

GIT repository(mod 10)

Kannada
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

GIT repository(mod 10)

Kannada
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Git Basics: Initializing a

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.

It’s useful for teamwork and safe coding!


Viewing Branches
- Command: `git branch`
- Lists all branches in the repository.
- Highlights the branch with an asterisk.
Creating a New Branch
- Command: `git branch branch_name`
- Example: `git branch feature-xyz` creates a new branch named 'feature-xyz'.
Switching Branches
- Command: `git checkout branch_name`
- Example: `git checkout feature-xyz` switches to the 'feature-xyz' branch.
Combined Command
The command git checkout -b branch_name does two things in one step:

1.Creates a new branch called branch_name.


2.Switches to that branch immediately.

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.

•Example: Merge changes from feature-xyz into the main branch.


Merge Conflicts
•Merge conflicts happen when two branches make changes to the same part of a file.

•Git will highlight these conflicts for you to fix


Resolving Merge Conflicts
- Open conflicting files and resolve issues manually.
- Use `git add file_name` to stage resolved files.
- Finalize with `git commit`.

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.

•Avoid working directly on the main branch.


Summary of Commands
•git init – Start a repository.
•git branch – List or create branches.
•git checkout – Switch branches.
•git merge – Merge branches.
Advantages of Git
•Git backs up your work automatically.
Git stores your changes locally when you commit and backs them up online when
you push to a remote repository like GitHub.

•Makes teamwork easier.


Multiple people can work on the same project using branches, avoiding conflicts,
and merging changes easily.

•Tracks all changes for better management.


Git keeps a complete history of every change, making it easy to see what was
modified, by whom, and when.
Conclusion
•Git helps manage project changes and teamwork.

•Learning to use commands like branching and merging makes coding more efficient.

You might also like