Skip to content

Andrew-Adel/Git_Lab2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Lab2 Git Part 1

1. create new project on local and push it to the remote repo

Screenshot from 2024-07-17 23-27-48 Screenshot from 2024-07-18 00-29-31

mkdir myproject
cd myproject
git init

echo "# Lab2 Git" >> README.md
git add README.md
git commit -m "Initial commit"

// create SSH key
 ssh-keygen -t ed25519 -C "andrew#########@gmail.com"

git remote add origin git@github.com:andrew/Git_Lab2.git

git push -u origin master

2. Create dev and test Branches, Create Files in dev Branch, and Push Changes

git checkout -b dev

echo "This is file1, Created By Andrew Adel" >> file1.txt
echo "This is file2 Created By Andrew Adel" >> file2.txt
git add file1.txt file2.txt
git commit -m "Add file1 and file2 in dev branch"
git push -u origin dev

git branch --show-current
git switch master
git checkout -b test
git push -u origin test

image image

3. Merge Changes into the master Branch and Push

git checkout master
git merge dev
git push -u origin master

image

4. Remove Branches Locally and Remotely

git branch -d dev
git branch -d test

git push origin --delete dev
git push origin --delete test

restore the branches
git reflog
git checkout -b dev 5b2d569
git checkout -b test 0e89d62
 

image

Lab2 Git Part 1

1. Create an annoted tag with tagnamr v1.4

git tag -a v1.4 -m "Version 1.4"

2. Push the Tag to the Remote Server

git push origin v1.4

3. List Tags Locally

git tag

4. Delete Tag Locally and Globally

//locally
git tag -d v1.4
//globally
git push origin --delete tag v1.4

5. What is Git Rebase? (With Example)

Git rebase is a way to integrate changes from one branch into another. It moves or "replays" the commits from one branch onto another, creating a linear project history.

A---B---C master
     \
      D---E feature

If you rebase feature onto master:

git checkout feature
git rebase master

it will act as

A---B---C---D'---E' feature

it is look like if D and E is commit after last update of master as if created and add after C update

6. Pull Request

A pull request is a way to request that another developer reviews and merges your changes into a branch of a repository. This is commonly used in collaborative projects to ensure code quality and manage contributions.

Steps to create a pull request:

  1. Push your branch to the remote repository:
git push origin dev
  1. Navigate to the repository on GitHub (or your Git hosting service).
  2. Click the "Pull requests" tab.
  3. Click the "New pull request" button.
  4. Select the branch you want to merge into (e.g., main) and the branch you want to merge from (e.g., feature-branch).
  5. Add a title and description for your pull request.
  6. Click "Create pull request".

7. Add Image to README.md

![Alt text](URL_to_image)
![My Project Logo](https://example.com/my_project_logo.png)

difference between clone, fetch, pull

1. Clone

Command:

git clone <repository-url>

Purpose:

  • Clones a repository from a remote server (like GitHub, GitLab, etc.) to your local machine.

Functionality:

  • Copies the entire repository, including all branches, commits, and history.
  • Sets up a local working copy of the repository.
  • Initializes a remote tracking branch (origin/master, origin/dev, etc.) that corresponds to the default branch (master or main) on the remote repository.

Typical Usage:

  • Used to initially download a repository from a remote server to start working on it locally.

2. Fetch

Command:

git fetch [<remote>]

Purpose:

  • Fetches changes from a remote repository to your local repository without merging them.

Functionality:

  • Downloads new data (commits, branches, tags) from a remote repository.
  • Updates the remote tracking branches (origin/master, origin/dev, etc.) to reflect the latest changes on the remote, but does not integrate those changes into your local branches.

Typical Usage:

  • Used to see what changes are available from a remote repository before deciding to merge or pull them into your local branch.

3. Pull

Command:

git pull [<remote>] [<branch>]

Purpose:

  • Fetches changes from a remote repository and merges them into your current branch.

Functionality:

  • Performs a git fetch to retrieve the latest changes from the remote repository.
  • Automatically merges the retrieved changes into the current branch (by default, this is the branch you are currently on).
  • Combines git fetch and git merge in a single command.

Typical Usage:

  • Used to update your current branch with the latest changes from a remote repository. It is effectively git fetch followed by git merge.

Key Differences

  • Clone: Downloads an entire repository from a remote server to your local machine, including all branches and history.

  • Fetch: Downloads new commits, branches, and tags from a remote repository to your local repository. It updates the remote tracking branches but does not integrate these changes into your working directory.

  • Pull: Downloads new commits from a remote repository and integrates (merges) them into your current working branch. It effectively combines fetch and merge.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published