Git and GITHub
Git and GITHub
A
multiple contributors to work on a project concurrently, without necessarily being connected to a
central server. In a DVCS, each user has a complete copy of the entire repository, including its
full history, on their local machine.
- **Decentralized Architecture**: Each user's local repository is a full and independent copy of
the project, containing the entire history of changes.
- **Offline Capabilities**: Users can work offline since they have a complete local copy of the
repository, enabling asynchronous collaboration from anywhere.
- **Branching and Merging**: DVCS excels in branching and merging workflows, enabling users
to create branches, work independently, and merge changes efficiently.
- **Redundancy and Backup**: Every user having a full copy of the repository ensures
redundancy and backup. If a central server fails, users can continue working with their local
copies, preserving the repository's history.
Ex: Git, Bazaar, and Mercurial.
entralized Version Control System (CVCS) is a type of version control system where there is a
C
single central repository that stores the entire history of the project and manages all changes
made by contributors.
- **Centralized Repository**: CVCS has a single central repository storing all project files and
version history.
- **Dependency on Central Server**: Users need to be connected to the central server for
version control operations, leading to potential bottlenecks and single points of failure.
- **Limited Offline Capabilities**: All version control operations rely on the central server, limiting
offline work and requiring synchronization once reconnected.
- **Collaboration and Access Control**: CVCS provides access control mechanisms for
managing user permissions and facilitates collaboration through centralized management of
files and version history.
- **Branching and Merging**: CVCS supports branching and merging but may have limitations
compared to distributed version control systems, with branches managed within the central
repository context.
Ex : subversion and concurrent version.
MERGE CONFLICT :
It is an event that occurs when git is unable to automatically solve the conflict due to conflicting
files or differences in code between two commits and requires human intervention to resolve this
issue.
1. **Conflict Occurs**: Git notifies you when merging if it finds conflicting changes in the same
part of a file between branches.
. **Open Files**: Use a text editor to open the conflicted files. Git marks the conflicting sections
2
with special markers.
. **Resolve Conflict**: Edit the conflicting sections to keep the changes you want, remove the
3
conflict markers.
4. **Save Changes**: Save the files after resolving the conflict.
5. **Stage Changes**: Use `git add` to stage the resolved files.
. **Complete Merge**: Use `git merge --continue` or `git commit` to complete the merge
6
process.
7.verify and Push Changes: After resolving the conflict and completing the merge, verify
t hat everything is as expected and push the changes to the remote repository if
necessary.
2. **Commit**:
- A commit in Git represents a snapshot of the project at a specific point in time. It
includes changes to one or more files, along with a commit message describing the
changes. Commits are the building blocks of the version history in Git.
3. **SCM**:
- SCM stands for Source Control Management, which is the process of managing
changes to source code over time. Git is an example of a distributed SCM system,
allowing multiple contributors to work on a project concurrently while keeping track of
changes made to the codebase.
5. **Checkout**:
- Checkout is the process of switching between different branches or commits in a Git
repository. When you check out a branch or commit, Git updates the files in your
working directory to reflect the state of the code at that specific point in time.
6. **Branching**:
- Branching in Git allows you to diverge from the main line of development and work on
new features or bug fixes in isolation from the main branch. Each branch represents an
independent line of development, and changes made in one branch do not affect other
branches until they are merged together.
8. **SHA**:
- SHA, or Secure Hash Algorithm, is a cryptographic hash function used by Git to
generate unique identifiers for commits, files, and other objects in a Git repository. The
SHA hash, also called the commit hash or object ID, uniquely identifies each commit in
the repository and is used for referencing commits in Git commands and operations.
● U segit push -u origin mainthe first time you pushcommits from a local
branch to a remote repository to set up tracking.
● Use git push <repo_name> <branch_name>to push commitsto a specific
branch on a specific remote repository without setting up tracking.
emote Repository :
R
It serves as a centralized storage location for your project's codebase and allows
collaboration among multiple developers by providing a centralized location to push and
pull changes.
GitHub,GitLab
ommon Commands:
C
git remote add <name> <url>: Adds a new remote repository with the specified name
and URL.
it remote -v: Lists all remote repositories associated with the current repository along
g
with their URLs.
it fetch <remote_name>: Fetches changes from the remote repository without merging
g
them into the local branch.
ile Patterns: You can specify file patterns to ignore specific files or directories. These
F
patterns can include wildcards to match multiple files or directories.
For example:
egation: You can use ! to negate patterns and include files that would otherwise be
N
ignored.
For example:
Ignore doc/notes.txt
#
doc/notes.txt
Exclude doc/server/arch.txt
#
!doc/server/arch.txt
REBASING :
ebasing in Git is the process of moving or reapplying a series of commits from one
R
branch onto another branch's tip. Instead of merging the changes, rebasing effectively
rewrites the commit history of the branch being rebased.
tashing in Git is a feature that allows you to temporarily shelve changes in your working
S
directory so that you can work on something else without committing those changes to your
repository. It's useful when you need to switch to a different branch or work on a different task
without committing your current changes.