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

Git and Github Workshop

The document outlines a workshop agenda covering Git and GitHub, including key topics such as initialization, staging, committing, branching, merging, and handling merge conflicts in Git, as well as operations like cloning, pulling, and pushing in GitHub. It emphasizes the importance of Git as a version control system for managing project changes and facilitating team collaboration. Additional resources for learning Git and GitHub are also provided.

Uploaded by

letuanhuynguyen
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)
10 views18 pages

Git and Github Workshop

The document outlines a workshop agenda covering Git and GitHub, including key topics such as initialization, staging, committing, branching, merging, and handling merge conflicts in Git, as well as operations like cloning, pulling, and pushing in GitHub. It emphasizes the importance of Git as a version control system for managing project changes and facilitating team collaboration. Additional resources for learning Git and GitHub are also provided.

Uploaded by

letuanhuynguyen
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/ 18

Git and Github

Workshop
Agenda

Git : Github :

1) Introduction 1) Introduction

2) Initialize Git 2) Clone

3) Stages 3) Pull

4) Commits 4) Push

5) Branches 5) Forks and Pull Requests

6) Merges
What is Git?

● Git is a version control system (system for managing changes) designed to track the
development of a project.
● It provides a variety of commands that are used to save new work, revert to a
previous save and split the project into different versions (called branches)
● Thus, in a programming environment, Git is essential for teams to track the
changes in their project.
● Moreover, it makes it easier for teams to communicate with each other and work
on a project smoothly
Why use Git?

● Git is the most popular version control system (Check stackoverflow survey 2023)
● Git is a definite requirement for an entry-level programming / engineering job
● Git organizes code chronologically
● Git organizes code with the help of branches
How to download Git?

1. Download Git at: https://git-scm.com/downloads


Initialize Git
1) Open Git Bash
2) Create or cd to a directory
3) Type git init to initialize a repository

● mkdir nameOfDirectory (name of directory) ● clear (clear command prompt)

● cd (change directory) ● git init (create a repository)

● pwd (see current directory) ● git help (provides a list of commands)

● git nameOfCommand -help (see options for a

command)
Stages
1) Modify or add any file
2) git status to see the report of the new changes
3) git add fileName or git add . to stage the files

Stages are essentially files that are added to the repository, ready to be committed

● ls (list the files in the directory)


● git status (check if the file is tracked, added to the repo)
● git add fileName (stages a file, adds it to the repo)
● git add . (stages all the untracked files to the repo)
Commits
1) Once that you staged the files, you can commit them with git commit -m “yourMessage”

Commits are the save points in your project, it is where we can observe changes between versions

● git commit -m “yourMessage” (creates a save point in your project)


● git log (view the history of commits, along with the author, date, message and commit #)
Branches
1) git branch nameOfBranch to create a new branch
2) git checkout nameOfBranch to change to a new branch
3) Make changes in the directory of that new branch
4) Stage and commit them

A branch is a different working area from the main repository. By default, the main branch is called master.

● git branch (listes the branches in the repo, the * indicates the current branch)
● git branch -a (See all local and remote branches)
● git branch nameOfBranch (creates a new branch)
● git checkout nameOfBranch (changes the working area to a new branch)
● git log nameOfBranch (see the changes made on a branch, press “q” to come back)
Merges
1) git checkout master to come back to the main branch
2) git merge nameOfBranch to merge the branch to the master branch

● git merge nameOfBranch (to merge a branch to the current branch)


● git branch -d nameOfBranch (to delete a branch)
Merge conflicts
1) Merge conflicts can happen before or during a merge.

2) A merge conflict prior to a merge indicates that there is a problem in the local repository (not common

to other developers)

3) When it happens after, it is because a branch is created from an initial branch and one or more file

that are in common with both branches conflict together. They conflict, because the initial branch has

changed from when the new branch was created. (conflict with another developer’s code)

4) Generally, git tries to resolve merge conflicts by its own, but when it can’t, it writes the unmerged

paths on the concerned files and the user has to fix them.

● git merge --abort (cancels the merging process)


What is GitHub

● Platform for version control using Git


● Cloud based service
● Allows to save, share and manage code
● Biggest platform used by developers

https://github.com/
Clone
1) git clone addressOfRepository to link a local repository to a GitHub repository

Creates a connection between a GitHub repository (remote repository) and a local repository.

● git clone addressOfRepository (links a local repository to a GitHub repository)


Pull
1) Makes changes to the repo on Github
2) git pull to update our local repo

Git pull retrieves the most recent version of the current branch we are on and overwrites it in our local
repository

● git pull
Push

1) Makes changes on the local repo


2) git push to upload them on the remote repo

Uploads the code on the current branch of a local repo to the remote repo

● git push
Pull Requests

Pull requests are made to contribute code to another developer’s repository. When creating a pull request,
the other developer is notified. They can see your commit with every new changes and decide whether or
not to accept it.
Forks Pull Requests

Creates a copy of a remote repository as one of your Pull requests are made to contribute code to another
own repos on GitHub. The original repo will not be developer’s repository.
affected by the changes on the fork. After forking a repo and making changes to it, we can
create a pull request and the other developer will be
notified.

They can see your commit with every new changes


and decide whether or not to accept it.
Additional Resources

https://www.w3schools.com/git/default.asp?remote=github

https://docs.github.com/en

https://www.atlassian.com/git/tutorials

You might also like