Git and Github
Git and Github
Course Overview:
What is Git?
Official site: https://git-scm.com/
Git is a free and open source distributed version control system designed to
handle everything from small to very large projects with speed and
efficiency.
Control & tracking of code changes over time
Git is a local tool. It's installed on your machine and therefore, only you can
use it as the user of this computer. Besides that, the code you have managed in
Git can only be accessed from that computer and not from anywhere else.
This means if you're not on your computer, and you want to work on a project
but you are where, somewhere else in the world, then you have a bit of a
problem. Besides the fact that if you lose your computer or if it crashes that
the code is lost. But that's another topic. So, Git is maybe just one part of the
solution we need to manage our development projects as efficient as possible.
This is where GitHub comes into play
What is GitHub?
Official Site: https://github.com/
GitHub is obviously used where the world builds software. We see that millions of
developers and companies build, ship, and maintain their software on GitHub.
So, it's the largest and most advanced development platform in the world.
So, GitHub seems to have a high focus on two developers, but what does this mean
in detail now? We learnt that GitHub is the largest development platform
and that many developers are using it for their projects. And why are developers
doing this? Well, because GitHub is a cloud hosting and collaboration provider
specifically made for developers, therefore also for web developers. It’s Cloud
Hosting Provider This means it's a service, which allows you to store your data, not
in the local environment, but in the Cloud. It is for free for basic use cases and also
the used cases we have here throughout this course. There are paid options mainly
required for companies and really bigger companies to well, be able to efficiently
manage the project.
GitHub is also for free. And it also is a collaboration provider. This means which Git
is a local tool, GitHub with the code being available in the Cloud, also allows us to
collaborate on our projects with other people. And this is very important because
if you think about big companies like Facebook, for example, or also smaller
companies for two, three, four, five or 10 developers work together on the same
project, well, these developers or we as developers need access to this code to work
on their specific parts of a website, for example. And this is what GitHub does in the
end. GitHub is a Git repository hosting provider to be even more precise here.
A Git repository is basically a Git-managed project in simple terms. So with that
capabilities, so these local capabilities of Git with managing that code efficiently,
with managing the history and also with tracking changes, and the capabilities of
GitHub with being able to host the code on a Cloud service and to enable that
great collaboration capabilities, well, this is how Git and GitHub are connected.
It's very important to understand though, that GitHub and Git are not generally
related. This relation only evolve because well, GitHub is the perfect addition to Git,
and turns out that many people using it are also using GitHub, therefore this is why
Git and GitHub sometimes are assumed to be well kind of one thing. But these are
two different tools, two different services, perfectly working and perfectly used
together by millions of developers in the world. So, this is what Git and GitHub are in
a nutshell.
Fig. Git & GitHub.
The Text Based Computer Interaction (Command Line What & Why?)
Mac Terminal:
The Basics:
Changing to D- Drive:
C:\>D:
D:\>
• Relative Paths:
D:\>cd Devops
D:\Devops>dir
Volume in drive D is Data
Volume Serial Number is 04F5-839B
Directory of D:\Devops
• Absolute Path:
D:\Devops\saiffaizalpanjesha -aws>dir
Volume in drive D is Data
Volume Serial Number is 04F5-839B
Directory of D:\Devops\saiffaizalpanjesha -aws
18/05/2022 17:49 <DIR> .
18/05/2022 18:08 <DIR> ..
12/04/2022 08:49 26,740 3646_Skills.pdf
18/05/2022 17:49 252 Devops Other Courses.txt
02/05/2022 00:01 1,700 Devops_Project_Key.pem
18/05/2022 02:25 176 devpos.txt
01/05/2022 23:47 135 new_user_credentials.csv
03/05/2022 21:57 1,868 Password.txt
6 File(s) 30,871 bytes
2 Dir(s) 275,885,756,416 bytes free
• cls :(Clear command prompt)
Contents:
• Theory – How Git Works?
• Installation & Deployment Environments
• Repositories, Branches and Commit
2. How to Launch Git in Windows. Launch Git Bash Shell. Launch Git GUI.
Step 2: Download the Visual Studio Code installer for Windows. Once it is
downloaded, run the installer (VSCodeUserSetup-{version}.exe). Then, run the file
– it will only take a minute. Accept the agreement and click “next.”
Fig. Visual Studio Install Success
Initializing the repository & creating the First Commit (“git init” and “git
commit”):
Untracked Files :
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
initial-commit.txt
nothing added to commit but untracked files present (use "git add" to track)
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: initial-commit.txt // initiated after added
updated file.txt
After Switch to master branch? Does it reflect the Working with Branches in
third branch (quickfix)?How to merge this branches ??
Merging Branches – The Basics
How to reserve the Steps and fix when something wrong with working
directory, Branches & Commit:
git ls-files
git restore: latest command for Undoing Unstaged Changes after git 2.2.23
The Commit which is not part of any branches is called detached head state.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 3207266 updated file.txt
updated file.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
detached-head.txt
no changes added to commit (use "git add" and/or "git commit -a")
Untracked files:
(use "git add <file>..." to include in what will be committed)
detached-head.txt
no changes added to commit (use "git add" and/or "git commit -a")
commit 320726669068faa962f8e245df7e3be52c76accc
Author: Saif Panjesha <[email protected]>
Date: Thu May 19 02:36:24 2022 +0530
updated file.txt
commit 18787b33e1bab418e8659ceb98f684c7e7e944a4
Author: Saif Panjesha <[email protected]>
Date: Fri May 20 00:01:25 2022 +0530
commit dc4a67141cb3c3529cdc7da6200e9600f0c56387
Author: Saif Panjesha <[email protected]>
Date: Thu May 19 15:02:23 2022 +0530
added second-commit.txt
commit 320726669068faa962f8e245df7e3be52c76accc
Author: Saif Panjesha <[email protected]>
Date: Thu May 19 02:36:24 2022 +0530
updated file.txt
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -
Fig.Not ignored
Fig. ignored folders “/ “command
git stash: temporarily shelves (or stashes) change you've made to your
working copy so you can work on something else, and then come back and re-
apply them later on.
Fig. shows we can identify different feature in our stash with the Message
Now this message we have to add in our Projects:
Let’s create a new branch called feature_branch and add file3.txt file
Fig. git reflog help us to get Git keeps track of updates to the tip of branches
Fast forward merge can be performed when there is a direct linear path from
the source branch to the target branch. In fast-forward merge, git simply
moves the source branch pointer to the target branch pointer without creating
an extra merge commit.
Let’s go and create first master branch with two files m1.txt first commit
Now, lets create a new branch called “Feature” branch with two files f1.txt
first commit and f2.txt second commit
Fig. Created feature branch with two files f1.txt and f2.txt
Fig. Created feature branch with two files and checking commit history
Fig. direct linear path from the source branch to the target branch
Fig. reset the head to remove extra commit
Note:
Squash will simply well, kind of squash or put together all the commits we
had in our feature branch into the latest commit so to say. So only one
commit is added to our master branch in the end.Therefore, if we now use git
merge --squash feature, you can see that we still have a Fast-forward merge
here but if we now check our Git log,
you see well, we don't have any commit, right?Now, what's wrong here?
Well, nothing is wrong. If you quickly scroll up a bit, you see that the head
was not updated here
because as I said, with the squash command, with the squash flag, we will
put together all the changes made in the feature branch into one single
commit
and this commit is not our f2 commit here, it is, in the end, as it contains all
the changes,but we have to create a separate commit
Fig. squash the previous commits into one.
Cleaning the directory:
Fig. Shows Complete history on the master branch of feature latest commit
(Merge branch “feature”)
Rebasing Theory:
From a content perspective, rebasing is changing the base of your branch from one commit
to another making it appear as if you'd created your branch from a different commit.
Fig. Workflow
Scenario: If two people in two different branches work on same file in the
end
Problem: Now, if we merge feature branch into master then all commits will
be going to add. But I want merge the specific typo commit of feature branch
into master branch.
Master branch:
Feature branch:
Lightweight tags:
Module Overview:
4. Verify your account by solving a puzzle. Select the Start Puzzle button to
do so, and then follow the prompts.
Fig. Account Verified
5. After you verify your account, select the Create account button.
6. Next, GitHub sends a launch code to your email address. Type that
launch code in the Enter code dialog, and then press Enter.
Fig. Enter the Code
7. GitHub asks you some questions to help tailor your experience. Choose
the answers that apply to you in the following dialogs:
8. On the Where teams collaborate and ship screen, you can choose
whether you want to use the Free account or the Team account. To
choose the Free account, select the Skip personalization button.
Tip
You can always upgrade your account later. See the Types of
GitHub accounts page to learn more.
Creating a repository:
Using Command:
git remote add origin https://github.com/SaifPanjeshah/gitHub1-basics.git
//add the remote connection from local repository
git push origin master //Bring our local changes, our local information on
remote repository
Fig. Successful push our local repository on GitHub
Fig. Successful push our local repository on GitHub via accessing through
Internet browser.
Now, how can we push our code with latest approach? Personal Access
Token?
Understanding the Personal Access Token:
Creating a token:
b. In the upper-right corner of any page, click your profile photo, then
click Settings.
How Can View this remote Branch feature2-new in git (local repository)?
git pull → used to fetch and download content from a remote repository and
immediately update the local repository to match that content(merge + fetch)
Fig. Shows full commit history of GitHub feature2 -new Branch in local
repository
Understanding Local Tracking Branches:
Now, to avoid this fatal error we have to create same branch as named in
remote tracking branches
Now let’s try for pull from remote tracking branches to local tracking
branches
Created New File :
Fig. Successful added to local tracking branches from remote vice versa
git clone is a git command line utility used to target an existing repository
and create a clone, or copy of the target repository.
Module Introduction:
Module Content:
• Cloud Storage: the single user uses GitHub, for example, to have a
cloud storage of his or her own Git projects.
• Portfolio Page: The single user might also use GitHub to present a
portfolio page, so a page presenting all the core skills, all the great
projects he or she worked on, or is working on.
• Collaboration: Collaboration GitHub means that either you have a
project, but you want to add other people, but to collaborate with you
on this project
• Contribution: It builds your resume by demonstrating that you can
collaborate with others on code.
Understanding The Account Types:
Remember: For Changing the repository public follow the Steps Vice Versa.
Pushing Commits to Public Repository
Fig. Shows with access other users can’t push the information our actual
GitHub
How GitHub Account Manager Security:
Fig. Shows with access other users can’t push the information our actual
GitHub
To resolve this problem:
Now, here the problem is even with access users can’t push the information
our actual GitHub. because of personal access token and we as account owner
can’t share the personal access token.
Remember: It’s better to get personal access token requests from another
users (Collaborators)
Official Site:
https://docs.github.com/en/account-and-profile/setting-up-and-managing-
your-personal-account-on-github/managing-personal-account-
settings/permission-levels-for-a-personal-account-repository
Limit Interactions:
Providing restrictions to another user.
Note : We cannot apply Limit to specific user only only on general conditions
that apply to certain users.
Code Review Limit: Restrict users who are permitted to approve or request
changes on pull requests in this repository.
Fig. Code review limits
Introducing Organizations:
we have some limits here when it comes to managing specific access rights
for collaborators of our projects
Now, trying to push the code from local branch git (VS Code) to check whether
the code is successful to cloud or not.
git clone https://github.com/Commitsa/Organization_repo1.git .
Definition: A fork is a copy of a repository that you manage. Forks let you make
changes to a project without affecting the original repository. You can fetch
updates from or submit changes to the original repository with pull requests.
1. Switch to the branch that you want to create a pull request for
Saiffaizal/Adding-Token
2. Click Create Pull Request. GitHub Desktop will open your default
browser to take you to GitHub
3. On GitHub, confirm that the branch in the base: drop-down menu is the
branch where you want to merge your changes. Confirm that the branch
in the compare: drop-down menu is the topic branch where you made
your changes.
Fig. Comparing Changes
If owner don’t like and don’t want to merge this pull request simply close this
pull request
Now, Owner Thinks a Second Way like the Fork design and wants to merge
the code
Close this Issue and create a new Issues Check again the Devops Docker
Container Project
README (as the name suggests: "read me") is the first file one should read
when starting a new project. It's a set of useful information about a project,
and a kind of manual. A README text file appears in many various places and
refers not only to programming.
Stars are all abouts likes on social media “Git and GitHub Basics “.