Git-workshop-2024
Git-workshop-2024
INTRODUCTION
Git is a Version Control System. Now, what's a VCS?
It is a system that tracks changes made in any set of files, usually
used for coordinating work among programmers.
Git shows what changes were made, when and by whom to a project.
INTRODUCTION
GitHub is an online software development
assistance and version control service.
INTRODUCTION
GITHUB
MORE ABOUT GITHUB
1. GITHUB is not GIT. Both are different
Things.
Features Of GitHuB…
1. Creating your first repository.
README
Starring and Following:
a. You can star the repositories you find interesting; so you may come
back to them later for contributing or just using them in
your own projects.
a. Follow the people whose progress and activity you want to follow on
GitHub. You will see the repos they starred, people they followed and
you get to learn a lot.
c. Flex your GitHub stats (my favourite part about Profile README ;)
): https://github.com/anuraghazra/github-readme-stats
d. Many more cool stuff to add (emojis, GIFs, skill badges, social media
handles):
https://towardsdatascience.com/build-a-stunning-readme-for-your-github-profile-9b80434fe5d7/
● MIT
Permissions-Commercial use,Modification,Distribution, Private use
Limitations-liability,warranty
● GNU
Permissions-commercial use,modification,distribution,patent use,private use
Limitations-liability,warranty
To collaborate with multiple people working on the same project, there are two
major options:
A merge will fail to start when Git sees there When this happens, it is not because of
are changes in either the working directory or conflicts with other developers’, but conflicts
staging area of the current project. with pending local changes.
Git fails to start the merge because these To solve this type of conflict, the changes
pending changes could be written over by the made need to be either committed or
commits that are being merged in. discarded, which can be done using git
stash, git checkout, git commit or
git reset.
A failure DURING a merge indicates a conflict Git will do its best to merge the files but will
between the current local branch and the leave things for you to resolve manually in
branch being merged. the conflicted files
This indicates a conflict with another Let us see how it happens and resolve it
developers code.
INSTALLATION
.
● After that it contains the info about the adjustment of Path environment. Keep
this to be the recommended option (i.e Git from the command line and also from
3rd-party software). Click on next.
● In the next page choose the Use the OpenSSL Library option(default option)
and click on next.
● In the next page choose the option (Checkout Windows-style, commit Unix-style
line endings) and click on next.
● Again click on next after checking Use MinTTY option. For all further pages stick
with the default options, hence click on next till you reach Installation option. Get
it installed and click on Finish.
INSTALLATION
● Go to Git official site and head over to downloads section for macOS
● Either use the homebrew method or the package installer →
1. HomeBrew method -
❏ Go to homebrew official site and copy the bash command and paste it in
your terminal and enter to install brew for mac
❏ Now run the command ‘brew install git’ to install git for your mac
❏ Download the package installer for mac from the Git official site
❏ Run it like a usual application installer on MacOS
Now , you’re all set to push/pull, commit,fork etc with the terminal on mac
----- We are now ready to move ahead with other functions -----
CONFIGURATION
● cd command: Allows you to traverse to other directories.
● pwd: displays present working directory
● mkdir/rmdir command: Allows you to make directory.
● touch command: Allows you to make file.
● Ls command: lists items in a directory
● Mv command: moves one file to another
● Rm command: removes a file
STAGING AREA
● Now, in order to insure if the correct file(s) has been
staged, we use the command:
“git status”
● This command shows you which files are being tracked,
which have been modified but are not being tracked and
which are not being tracked.
CHECKING STATUS
● “git show” is a command line utility that is used to view
expanded details on Git objects such as blobs, trees, tags,
and commits
● For example:
git show
● There are two ways of viewing history logs:
● “git log” : displays all of the commits in the repository’s
history.
● “git reflog” : displays the record when the tips of branches
and other references were updated.
Viewing Log
● Now comes the committing part.
● If all things are good you may want to
commit changes to release the
new version of your project.
● To do this we will use:
“git commit” command
● Type: “git commit -m <message>”
● Here take care of the message part as it should be concise,
clear and short.
COMMIT CHANGES
● Let’s suppose you want to revert back to last version of the file as
the current version is buggy or you made some serious mistake.
● So first type: “git diff HEAD” (allows you to compare the file
version in your working directory with the file version last
committed in your remote repository)
● To move back to last version ,first check the commit id using the
command:
“git reflog”
BRANCHING
Branches give you the freedom to independently work on different modules
(not necessarily though) and merge the modules when you finish developing
them. It might sound a cumbersome process, but git branches are swift to be
created and destroyed. Just a simple command can perform these processes,
and they are very cheap, considering the size they take. Branches in Git help the
team, which are in different parts of the world, work independently on
independent features that would ultimately combine to produce a great project.
Moreover, the branches are very flexible. Using branches does not mean you are
using them for different features.
BRANCHING
Operations in Git Branches
● The git branch Command
○ To list all branch name in the repository
○ Create a branch
■ git branch <branchname>
● The git checkout Command
○ To switch between different branches
■ git checkout <branchname>
● Delete a branch
○ git branch -d <branchname> (will show error if you are on that branch)
○ git branch -D <branchname> (force deletes the branch)
BRANCHING
Some more Operations in Git Branches
● To clone a specific branch
○ git clone -b <branchname> <repo_url>
● The create + checkout Command
○ git checkout -b <branchname>
● Push to a specific branch
○ git push -u origin <branchname>
● Merging two branches (Note : you should be on the branch in which you
want to merge a specific branch)
○ git merge <branchname> (here branchname is the branch you want to
merge)
BRANCHING
Why Branching? Let’s see an example!
Imagine you're developing a video game. The main game is what you've been
working on, and it's your core project. You want it to be fun and bug-free.
● Branches: Now, think of branches like creating alternate versions or levels of the
game. Each branch is like a separate version of your game where you can try out
new features or fix specific problems.
● Making Changes on a Branch: Let's say you want to add a new character or a cool
weapon to your game. You wouldn't want to mess up the main game while you're
working on this, right? So, you create a branch, like a copy of your game. On this
branch, you can experiment, make changes, and add new stuff without affecting the
main game.
BRANCHING
● Testing and Tweaking: Once you've made the changes on your branch, you can play
and test your game to make sure everything works perfectly. If you're happy with it,
you can then merge, which means you take the changes you made on your branch
and add them to the main game. It's like bringing the new character or weapon you
created into the main game.
● Keeping Things Organized: Branches help you keep your project organized. You can
have one branch for adding new characters, another for fixing bugs, and so on. If
something doesn't work out on a branch, you can delete it without affecting the main
game.
● Collaboration: If you're working with a team on your game, branches also allow each
team member to work on their part independently. They can create their branches,
make changes, and then merge them into the main game when they're ready.
BRANCHING
Creating a Branch
Creating a Branch in Git
BRANCHING
Switching between branches
Creating a Branch in Git
● Switching in Git:
○ To switch between branches in Git, it's as simple as changing channels on your TV.
○ Just use git checkout <branch-name> to switch to the branch you want.
● Safety First:
○ Remember to save your work before switching, just like saving your game progress.
○ This helps avoid conflicts and keeps everything smooth.
BRANCHING
Making changes
Making Changes in Git
BRANCHING
Merging changes
Making Changes in Git
● You can merge your changes into other branches (main) using the git merge main
command followed by the branch name.
BRANCHING
Deleting branches
● git branch -d <branch>:
○ Use this command to delete the specified branch.
○ It's a safe operation because Git prevents you from deleting the branch if it has unmerged changes (changes that
haven't been incorporated into other branches yet).
○ Ideal for cleaning up branches that have already been merged into the main branch.
BRANCHING
Best practices
1. Use Descriptive Branch Names:
2. Branch from a Stable Base:
3. Frequent Commits:
4. Testing:
5. Branch Cleanup:
6. Documentation:
7. Communication:
8. Use Version Tags:
BRANCHING
Key Takeaways
● Use git branch to list all branches.
● Create and switch to a new branch with git checkout -b <branch name>.
● Switch between branches using git checkout <branch-name> (or git switch
<branch-name>).
● In Git, make edits to files in the working directory, stage changes with git add ., and commit with
git commit.
● Merge changes from another branch into the current branch with git merge <other branch>.
● The final step in integrating changes into the main codebase is to merge pull requests using git
merge main.
● git branch -m <branch> Rename the current branch to <branch>.
● git branch -a List all remote branches.
BRANCHING
● So, branching is like creating different versions of your game to experiment
with new features or fixes while keeping your main game safe and
improving it step by step. It's a smart way to develop and collaborate on
bigger projects!
BRANCHING
Pushing
Pushing
Pushing changes to GitHub is like showing your latest drawings to your friends. Here's how it works:
● First, double-check that you're in the right place (the right branch). You wouldn't want to show your math homework to your art
class!
● Then, use the git push command. It's like pressing a button that sends your drawings to a special folder on the internet
where your friends can see them, just like putting your artwork in a gallery for everyone to enjoy.
BRANCHING
Pull Request
Creating a Pull Request on GitHub
BRANCHING
Merging Pull Request
Merging Pull Requests
BRANCHING
Some more Operations in Git Branches
● To clone a specific branch
○ git clone -b <branchname> <repo_url>
● The create + checkout Command
○ git checkout -b <branchname>
● Push to a specific branch
○ git push -u origin <branchname>
● Merging two branches (Note : you should be on the branch in which you
want to merge a specific branch)
○ git merge <branchname> (here branchname is the branch you want to
merge)
BRANCHING
$ mkdir git_live
$ cd git_live
$ git init
$ nano
Type the following basic html code
<body style="background-color:red" ></body
Ctrl+x Y file_name.html
$ git add .
$ git commit -m “initial commit”
Branching
$ git checkout -b blueBG
$ git checkout -b greenBG
$ git branch
$ nano file_name.html
<body style="background-color:green" ></body
Ctrl+x Y file_name.html
BRANCHING
Branching
$ git checkout -b blueBG
$ git checkout -b greenBG
$ git branch
$ nano file_name.html
<body style="background-color:green" ></body
Ctrl+x Y file_name.html
RELOAD
$ git add .
$ git commit -m “greenbg added”
BRANCHING
DELETING A BRANCH
$ git branch
$ git branch -d greenBG
$ git branch
MERGING
$ git checkout master
$ git merge blueBG
RELOAD
$ git branch -d blueBG
$ git branch
BRANCHING
What is a Git merge conflict?
● A merge conflict is an event that occurs when Git is unable to automatically
resolve differences in code between two commits.
● When all the changes in the code occur on different lines or in different files,
Git will successfully merge commits without your help.
● However, when there are conflicting changes on the same lines, a “merge
conflict” occurs because Git doesn’t know which code to keep and which to
discard.
MERGE CONFLICT
Conflict Markers
<<<<<<< HEAD
=======
● You can either save the changes from both the files by just removing the
conflict markers i.e “<<<<<<< HEAD”, “=======” and “>>>>>>> “Branch
Name””
● Or save either of the change by just keeping the content within the either
pair of conflict markers i.e. “<<<<<<< HEAD” and “=======” or
“=======” and “>>>>>>> “Branch Name””
Resolving on GitHub
So, How do we exactly
do this on GitHub?
● Frequently Pull/Push code to the mainline branch, which makes it less
likely to have conflicts and they’ll be smaller when they happen
● Make devs work on independent parts of the code.
● Frequent Communication with your fellow team mates
GitHub Actions
Workflows
A workflow is a configurable automated process that will run one or more jobs.
Eg: You can have a workflow that adds a label every time someone opens a new issue
A repository can have multiple workflows, each of which can perform a different set of tasks.
- Triggering a workflow
Workflow triggers are events that cause a workflow to run. These events can be:
● Events that occur in your workflow’s repository
● Events that occur outside of GitHub and trigger a repository_dispatch event on
GitHub
● Scheduled times
● Manual
GitHub Actions
Your workflow contains one or more jobs which can run in sequential order or in parallel.
Each job will run inside its own virtual machine runner, or inside a container, and has one
or more steps that either run a script that you define or run an action.
GitHub Actions
Components of GitHub actions
● Events
A specific activity in a repository that triggers a workflow run.
Eg: Activity can originate from GitHub when someone creates a pull request, opens an issue
or pushes a commit to a repository.
● Jobs
A job is a set of steps in a workflow that execute on the same runner. Each step is either a shell
script that will be executed, or an action that will be run. Steps are executed in order and are
dependent on each other.
● Actions
An action is a custom application for the GitHub Actions platform that performs a complex but
frequently repeated task.
GitHub Actions
Life Cycle of an Application !
At
Can we do something to automate
???????
🤔🤔
At
Introduction to CI/CD
a. What is CI ( Continuous Integration )
b. What is CD ( Continuous Deployment / Continuous Delivery )