0% found this document useful (0 votes)
10 views46 pages

תרגול 2

Version control (VC) is a system for managing changes to documents and code over time, allowing for error recovery, parallel development, and conflict resolution. Git is a distributed version control system that enables local development without network access and supports branching and merging workflows. The document provides instructions on installing Git, setting up repositories, and collaborating through platforms like GitHub, as well as commands for managing files and branches.

Uploaded by

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

תרגול 2

Version control (VC) is a system for managing changes to documents and code over time, allowing for error recovery, parallel development, and conflict resolution. Git is a distributed version control system that enables local development without network access and supports branching and merging workflows. The document provides instructions on installing Git, setting up repositories, and collaborating through platforms like GitHub, as well as commands for managing files and branches.

Uploaded by

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

Version control (git)

1969. Hamilton stands next to the


software she produced for the Apollo
project
What is Version Control (VC)?

● The management of changes to documents, programs,


websites and more, over time
● A logical way to organize versions during development
● Version control keeps track of every modification to the
files in a special database.
Why Do I Need Version Control (VC)?
● If a mistake is made, you can turn back and compare
earlier versions of the files
● Develop features in parallel with other collaborators
● Conflict resolution
● Rollback and undo changes to source code
Why Do I Need Version Control (VC)? Cont.
● Bugs found later (after deployment) can be tracked down
even if different versions have been released
● Assist parallel development, but there is always room for
human error
● Version Control Systems (automated) try to fix that.
Git

Git is a distributed revision control and source code management


system
● It is distributed because no network access is needed to proceed in
development
○ The entire repository (repo) with all its history is stored locally.
● Once in a while, the local repo is merged with an online central repository
that everybody shares
○ You can use git at home without a remote repo, then later change your mind.
● The Graph is “pointer” based
● We are going to focus on GIT in this course as a version control
system
Version Control (VC) - The Structure, Workflow

● The workflow in version control is the form of branches.


● One trunk (main) is preserved as a stable version of the program.
● Added features are done on separate branches, then later merged
once stable and complete.

● Tags may be placed to indicate


full (distributable) revisions.
Working With Git

● Command line interface ✔


● GUI Tools ✖
● https://git-scm.com/
Git - commands

Git is essentially a script


based language
Getting Git on your computer-
Option 1 - Windows native approach

First make sure you have PowerShell installed on your computer, if


you don’t have PowerShell you can install it from Microsoft Store, or
you can follow this link to install it.
Now from the PowerShell run: winget install –id “Git.Git”
Getting Git on your computer-
Option 2 - install Git from the site

In case you’re using Linux or you encountered


some problem with the previous slide, you can view
options regarding installation of Git from this link.
You may use all the suggested default settings
when you install Git.

Work with git bash.


Git Setup

● git config --global user.email "[email protected]"


● git config --global user.name "Your Name"
● git config --global color.ui true
Starting a New Repo

$ mkdir testProject
$ cd testProject
$ git init --initial-branch=main

Initialized empty Git repository in current directory

.git - a folder where all git data is saved (remember git is


decentralized)
*Notice that is hidden
My First Commit

$ git status
$ touch README.txt
$ git status
$ git add README.txt
timelin
$ git status e
$ git commit -m “Create a README”
$ git status

main
Version Control (VC) - The Structure, Workflow

● The workflow in version control is the form of branches.


● One trunk (main) is preserved as a stable version of the program.
● Added features are done on separate branches, then later merged
once stable and complete.

● Tags may be placed to indicate


full (distributable) revisions.
What Just Happened?
Lets Add Multiple Files

$ git add LICENSE README.txt


or timelin
e
$ git add -all / git add .
$ git commit -m “Add LICENSE and finished README”

main
Git Diff

Let's change the README file


$ git diff README

this command will show you all the changes that are in the working
directory and not the staging area. meaning that after “git add .” you
won’t be able to view those changes.
BRANCHING
pizza

$ git branch pizza

$ git branch
pizza HEAD
* main

main
BRANCHING
pizza

HEAD
$ git checkout pizza

$ git branch
* pizza
main

main
BRANCHING
pizza

HEAD
$ git add pizza.txt
$ git commit -m “Tasty pizza”

$ ls
README.txt pizza.txt LICENSE

main
BRANCHING
pizza

$ git checkout main


$ls
README.txt LICENSE
HEAD

main
BRANCHING
pizza

HEAD
$ git checkout pizza

$ls
README.txt LICENSE pizza.txt

main
main

Merging HEAD pizza

$ git checkout main

$git merge pizza


Dealing with a conflict

● Create a branch
● Change code.cs in branch
● Merge: conflict
● Fix conflict via text editor
● Add & commit
main

Clean Up

$ git branch -d pizza HEAD

Deleted branch pizza

Note: in your kanban project you won’t


delete your branches, just leave them
How To Share?
Git ≠ GitHub
GitHub ≈ GitLab ≈
BitBucket
Getting started with GitHub

Open an account in GitHub With your University


email address (it’s important for the milestones).
creating a GitHub repository

● After you signed in with your university email address to GitHub,


go to “Your repositories”.
● Afterwards click “new”
creating a GitHub repository

● Be sure to name your repository.


● do not add any files to the repository,
it needs to be completely blank.

● Note: when you start to work on your


project only one teammate needs to
create the Repository, the others will
need to clone it.
creating a GitHub repository

● After you’ve created your repository you’ll have a remote


repository on GitHub and a url for it .
Git Remote

Create a github/gitlab/bitbucket repo with no files


$ git remote add origin https://.../.../...git
Final Step

When the code ready to upload to the server:


$ git push -u origin main

*main indicates the name of the branch. You can also use:
$ git push -u origin --all
Collaboration
Collaboration

Let's say that another user want to collaborate:


$ git clone ……git
A Branching Model
The branching method in this
course
Feature Branch
● Branch of develop
● Primary working branches for an individual(s)
● When new feature is finished
○ Merge into develop

○ Code reviews (If applicable)

○ Hope it doesn’t break develop (it might)

● Temporary branches
● Can be many feature branches being developed in
parallel
● If the feature is a failure
○ Delete the branch without merging into develop
Pull requests
“Pull requests let you tell others about changes you've pushed to a branch in a
repository on GitHub. Once a pull request is opened, you can discuss and review
the potential changes with collaborators and add follow-up commits before your
changes are merged into the base branch.” - Git documentation.
Locally merge VS Remote pull requests
The invariant of the base branch, or in Git case the main branch, is that the base
branch is always finished, meaning that it does not hold unfinished features, code with
bugs, or code that does not compile.
Therefore in this course We will Save Pull Requests just for merging finished feature
branch to the main, while merging a feature branch to another feature branch can be
done with local merging.

In addition, before we pull request branchA into develop, we first merge develop into
branchA.

Note: In your project, If a team member A opened a pull request from a feature branch
to the main, in no circumstances team member A is allowed to approve the pull request.
it needs to be reviewed and approved by other team members.
erge
m

pull
requ
e
st
Ignoring Files

● Create a file called .gitignore


Write the file names that should be ignored by git
Commit the file

● Example:
● https://www.toptal.com/developers/gitignore
GIT TIMELINE HISTORY

$ git log
commit e5c36be744223ef3789d870d12ea6bf676360248
Author: goolig <[email protected]>
Date: Wed Jan 30 10:48:19 2019 +0200
:
Add katz notebook
:
commit b6954141cba3962478bca1c83954ea25486742a1
Author: goolig <[email protected]>
Date: Wed Jan 30 09:55:26 2019 +0200
:
_Add preproc pickles
:
Additional Tutorials

● https://www.w3schools.com/git/default.asp?remote=github
● If any contradictions with class appear, refer to the class material
as the ground truth.
● There are many other good tutorials available.

You might also like