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

git ass2

This document provides a comprehensive guide on using Git and GitHub, covering topics such as initializing projects, creating branches, pushing to remote repositories, and managing collaborations. It explains the importance of .gitignore files, the differences between git fetch and git pull, and how to track large files using Git LFS. The content is structured in a way that outlines essential commands and best practices for effective version control and collaboration in software development.

Uploaded by

ahmedsamer6788
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

git ass2

This document provides a comprehensive guide on using Git and GitHub, covering topics such as initializing projects, creating branches, pushing to remote repositories, and managing collaborations. It explains the importance of .gitignore files, the differences between git fetch and git pull, and how to track large files using Git LFS. The content is structured in a way that outlines essential commands and best practices for effective version control and collaboration in software development.

Uploaded by

ahmedsamer6788
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

GIT & GITHUB

REMOTE REPOSITORIES & IGNORE FILES


CREATED BY: AHMED SAMIR AWED ALI
MAJOR: MATHEMATICS AND COMPUTER SCIENCE
ID :352151186
AGENDA

INITIALIZE THE MAKE BRANCHES PUSH ON THE COLLABORATION PULL CHANGES TRACK IMAGES
PROJECT REMOTE REPO AND VIDEOS
1- INITIALIZE THE
PROJECT

• new repository from the GitHub


• copy the https URL
https://github.com/ahmedsamir45/image-to-caption-
research-project.git
• Write in your local terminal directory
git clone https://github.com/ahmedsamir45/image-to-
caption-research-project.git
1- INITIALIZE THE
PROJECT

• make your updates and files and you


will work on default branch main.
• Add to the index:
git add . or git add * or git add pattern.
• If all things ok add to local repo and
Make commits:
git commit + add long message on editor
or
git commit –m “ short message description ”
2- MAKE BRANCHES

1. Feature Branching

Description: Create a new branch for each feature or bug fix.


Best for: Small to medium projects.
Steps:
1.Create a branch: git branch feature/new-feature
2.Switch to the branch: git checkout feature/new-feature
3.Make changes and commit them.
4.Push the branch to GitHub: git push origin feature/new-feature
2- MAKE BRANCHES

2. Release Branching
3. GitFlow
Description: Use separate branches for each release. Description: Use separate branches for features, releases,
and hotfixes.
Best for: Projects with set release dates.
Best for: Large, complex projects.
Steps: Steps:
1.Create a release branch: git branch release/v1.0 1.Create feature branches from develop.
2.Merge feature branches into the release branch. 2.Merge feature branches into develop.
3.Tag the release branch for deployment. 3.Create release branches from develop.
4.Merge release branches into master.
2- MAKE BRANCHES

Example

1- check the branch:


git branch
2- create new branch:
git branch research
git branch research notebook
3- change the branch:
git switch research
- You can make your commits about the research here
and go back to main: git switch main
3- PUSH ON REMOTE REPO
Examples of remote repository
• GitHub: Known for its large community and ease of use,
GitHub is popular among individual developers and open-
source projects. It offers robust CI/CD pipelines through
GitHub Actions and a vast ecosystem of third-party
integrations.
• GitLab: Offers a comprehensive suite of DevOps tools,
including built-in CI/CD capabilities, security testing, and
project analytics. It is open-source and provides a self-hosted
option, making it suitable for enterprises.
• Bitbucket: Specializes in integration with the Atlassian suite
of tools like Jira and Confluence, making it ideal for teams
already using these products. It offers free private
repositories for small teams.
3- PUSH ON REMOTE REPO
What is git push ?
git push is used to upload your local commits to a remote
repository (like GitHub, GitLab, or Bitbucket). It sends the
changes from your local branch to the corresponding
branch on the remote repository.

How git push Works ?

• You make changes in your local repository.


• You commit the changes using git commit.
• You push the changes to the remote repository using git push.
3- PUSH ON REMOTE REPO
• Adding a remote repository: • If the branch doesn't exist on the remote, Git
git remote add origin https://github.com/user/repo.git
may ask you to set the upstream branch using:
git push --set-upstream origin branch-name
• Viewing remote repositories:
git remote –v
• Push Changes to a Remote Repository “push your main
branch”:
git push origin main
• Pushing a Specific Branch:
git push origin research
• Pushing All Local Branches
git push --all origin
IGNORE FILES
• .gitignore files are essential in Git for specifying files
or directories that should be intentionally ignored by
Git. Here's a detailed overview of .gitignore files,
including their purpose, usage, and common patterns.
You can choose a template from GitHub in the remote
repos Ex: python.
• Why Use .gitignore Files?
Avoid Committing Transient Files: Files like build artifacts,
IDE configuration files, and temporary files should not be
versioned.
Improve Git Commands: By ignoring irrelevant files, Git
commands like git status and git add become more
efficient.
Collaboration: Shared .gitignore files ensure that all team
members ignore the same files, maintaining consistency
across the project.
4- COLLABORATIONS
1. Repositories 4. Issues
•Definition: Central locations where all project files are •Definition: Used to track bugs, enhancements, or tasks within
stored. a project.
•Use: Team members can clone repositories to work •Use: Assign issues to team members and track progress.
on local copies.
5. Discussions
2. Branches •Definition: A feature that allows teams to discuss topics
•Definition: Separate lines of development that allow related to their project directly within GitHub.
multiple versions of a project to coexist. •Use: Use discussions to keep conversations organized and
•Use: Create feature branches for new features or bug linked to specific parts of the project.
fixes, then merge them into the main branch.
6. Collaborator Access
3. Pull Requests •Definition: Granting permissions to team members to
•Definition: A way to propose changes to a repository contribute to a repository.
by creating a pull request, which can be reviewed and •Use: Invite collaborators to your repository to allow them to
merged. push changes.
•Use: Submit pull requests for code reviews before
merging changes into the main branch.
5- PULL CHANGES
A- fetch
❖ When you run git fetch, it Fetching Everything (All Branches): git fetch origin
downloads the latest changes
from the remote repository check the remote-tracking branches: git branch -r
without merging them into your
local branch. Fetching a Specific Branch: git fetch origin feature-branch
❖ Your local branch remains
unchanged until you manually After fetching, you can compare changes without merging:
merge the fetched changes. git diff branch-name origin/branch-name

Pulling All Remote Branches ( Not Recommended)


If you decide to merge the updates into your local branch:
for branch in $(git branch -r | grep -v HEAD); do git checkout branch-name # Switch to the branch
git checkout ${branch#origin/} git merge origin/branch-name # Merge fetched changes
git pull origin ${branch#origin/}
done
5- PULL CHANGES
b- pull
How git pull Works

❖ git pull is basically git fetch + git merge in one step.


❖ It downloads the changes from a specific remote branch and
merges them into your currently checked-out branch.

git pull only pulls one branch at a time.


By default, it pulls updates only for the branch you are currently
on.

git pull origin feature-branch


5- PULL CHANGES

Summary: git fetch vs git pull

Merges Affects Multiple


Command What It Does Best Use Case
Automatically? Branches?
Downloads updates
Checking for
from the remote Yes (All remote
git fetch No updates before
repository without branches)
merging manually.
merging them.
Downloads and
automatically
No (Only one Getting the latest
git pull merges updates Yes
branch) changes quickly.
into your current
branch.
6- TRACK IMAGES AND VIDEOS

Look at this problem

Tracking Large
Files in GitHub:
Git LFS | by
Lucas Leiberman
| Medium
6- TRACK IMAGES AND VIDEOS

Git LFS
(Large File Storage) is an extension that helps manage large
binary files, such as images, by storing them outside the main Git
repository. This approach keeps your Git repository lightweight
and improves performance.

When to Use Git vs. Git LFS


Use Git for:
Small binary files (e.g., icons, small images) where the overhead of Git LFS is not justified.
Text files or any files where version control through diffs is beneficial.

Use Git LFS for:


Large binary files (e.g., high-resolution images, videos) to avoid bloating your Git repository.
6- TRACK IMAGES AND VIDEOS
# Initialize a new Git repository
git init

# Install Git LFS


git lfs install

# Track .jpg and .png files


git lfs track "*.jpg" "*.png"
Example
Workflow # Add and commit .gitattributes
git add .gitattributes
git commit -m "Track images with Git LFS"

# Add an image file


git add example.jpg

# Commit the image


git commit -m "Add example image"

# Push changes to remote repository


git push origin main
Summary
Initialize the Project
Pull Changes
• Clone a repository: git clone <repo-url>
git fetch (check updates) vs. git pull (fetch & merge)
A black background with a black square

AI-generated content may be incorrect.

• Track changes: git add . → git commit -m


"message" Ignore Files
Branches
.gitignore prevents tracking
• Create: git branch feature/new- unwanted files (e.g., logs,
feature temp files)
• Switch: git switch feature/new-
feature Push to Remote Repo
•Merge & manage versions with GitFlow
• Add remote: git remote add
Collaboration origin <URL>
• Push changes: git push origin
•Use pull requests for code reviews main
•Track progress with issues & discussions Track Images & Videos
•Grant access to collaborators
Use Git LFS for large files (git lfs track "*.jpg")

You might also like