About Git
About Git
What is Git :
5. Open Source Projects: Most open source projects use Git for version
control. Learning Git allows you to contribute to these projects.
5. Merge branches: Use "git merge" to merge changes from one branch
into another. This combines the commits from both branches into a
single branch.
6. Push and pull changes: Use "git push" to upload your local commits
to a remote repository, and "git pull" to fetch and integrate remote
changes into your local repository.
Commands :
Merging is the process of taking the changes from one branch and
integrating them into another branch. It’s how you combine the work
done separately in different branches back into a single branch.
For example, if you’ve been working on a feature branch and want to
bring those changes into the main branch, you merge the feature
branch into main.
When you merge, Git looks at the history of both branches and tries to
automatically combine changes.
If the changes were made in different parts of the files , Git
merges them smoothly.
If the same part of the code was changed differently in both
branches, Git will raise a merge conflict, which you need to
resolve manually.
Workflow:
Switch to branch you want to merge into
# Git checkout master
Run the merge command, specifying the branch you want to
merge from
# git merge mybranch2
Fix the merge conflits if arises
Stage the clean and fixed file
#git add .
Commit the merge to complete
# git commit
Git will either Complete the merge automatically if there are no
conflicts, or Pause and ask you to resolve conflicts.
Commands :
Merge conflicts happen when Git tries to combine two branches, but finds
that the same parts of the same files have been changed differently in each
branch. Since Git can’t automatically decide which change to keep, it asks
you to manually fix the conflict.
Because two branches modified the same line(s) of code or close parts in
different ways.
In the conflicted file, Git adds special markers to highlight the conflicting
sections, like this:
When you encounter merge conflicts in Git, your code editor or Git tools
often give you options to resolve the conflict by choosing:
conflict markers :