Git-GitHub-Complete-Learning-Material

image

Introduction

1. What is Git

image

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.
It can be used to track changes in the source code when multiple developers to work together.
When multiple developers work together in a given project it’s version keeps on changing and this can be controlled and managed by git.
Git is free and open-source software distributed under the GPL-2.0-only license.

2. What is GitHub

image

GitHub is a for-profit company that offers a cloud-based Git repository hosting service. Essentially, it makes it a lot easier for individuals and teams to use Git for version control and collaboration.
GitHub’s interface is user-friendly enough so even novice coders can take advantage of Git. Without GitHub, using Git generally requires a bit more technical savvy and use of the command line.
Additionally, anyone can sign up and host a public code repository for free, which makes GitHub especially popular with open-source projects.
Do check: github.com

3. Git Download

For downloading Git first go to https://git-scm.com/downloads

and download the installer as per the instruction given in the webpage for the required OS.Next open the installer and proceed with all the default settings.And after successful installation , you can verify it by typing the following command in terminal :

image

git --version

press enter…
If something version number is displayed it means that git has been successfully installed in your system , if not try installing git again by following the steps given above.

Git Commands

4. Git config

The git config command is a convenience function that is used to set Git configuration values on a global or local project level. These configuration levels correspond to .gitconfig text files. Executing git config will modify a configuration text file.

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

5. Git Init

This is basically performed to initialise a folder/repository so as to perform git operations like adding, committing etc.
Inorder to initialise local repositry with git we can run the following command to the respective folder location using terminal:

git init

press enter…
Great… now your local repository has been initialized with git.
image

6. Git add

The git add command is used to add file contents to the Index (Staging Area).This command updates the current content of the working tree to the staging area.
It also prepares the staged content for the next commit.
Every time we add or update any file in our project, it is required to forward updates to the staging area.

git add --all

7. Git commit

After you do changes in your code you will do “commit”.
Commit set a message about the changes you were done.
The commit also saves a revision of the code and you can revert the code to any version anytime in one click.

git commit -m"REQUIRED_COMMIT_MESSAGE"

REQUIRED_COMMIT_MESSAGE is the one which we add to identify each commits that we hae done.

8. Git remote

A remote in Git is basically a bookmark for a different repository from which you may wish to pull or push code.
The bookmarked repository may be on your local computer in a different folder, on remote server, or it may even be the repository itself.

git remote add origin REPOSITORY_URL

REPOSITORY_URL is the url of the repository to which we have to push the code.

9. Git push

The git push command is used to upload local repository content to a remote repository.
Pushing is how you transfer commits from your local repository to a remote repo.
Remote branches are configured using the git remote command.

git push origin BRANCH_NAME

BRANCH_NAME is the name of the branch from which the code has to be pushed.

10. Git branch

Git branches are effectively a pointer to a snapshot of your changes. When you want to add a new feature or fix a bug—no matter how big or how small—you spawn a new branch to encapsulate your changes. … Instead of copying files from directory to directory, Git stores a branch as a reference to a commit.

git branch shows the list of branches in your project
git branch NEW_BRANCH_NAME creates a new branch
git checkout BRANCH_NAME switches the branch to your prefered one.

11. Git Checkout

The Git Checkout command is used to switch between branches in a repository.
This command is used to switch from one branch to another:

git checkout branch_name

This command creates a new branch and also switches to it:

git checkout -b branch_name

12. Git log

Git log is a utility tool to review and read a history of everything that happens to a repository. Generally, the git log is a record of commits.

git log

This command will display the last commits.

13. Git status

The git status command is used to display the state of the repository and staging area. It allows us to see the tracked, untracked files and changes.
This command will not show any commit records or information.

git status

This command lists all the files that have to be committed.

image

14. Git merge

Git merging combines sequences of commits into one unified history of commits.

git merge branch_name

This command merges the specified branch’s history into the current branch.

image

15. Git clone

This feature helps us to create a copy of a repository in our local system from the GitHub.
By doing so we can test that code and see the output, if we want we can make additional features etc.

git clone REPOSITORY_URL

This REPOSITORY_URL will be the url of the required repository which is to be cloned to our local machine.

image

Some GitHub Processes

16. GitHub Fork

A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project.
Once you have forked a repo, you own your forked copy. This means that you can edit the contents of your forked repository without impacting the parent repo.
You can fork any repo by clicking the fork button in the upper right hand corner of a repo page.

image

17. Git pull

The git pull command is used to fetch and download content from the tracking remote repository and immediately update the local repository to match that content.
The git pull command is actually a combination of two other commands, git fetch followed by git merge
The command used to pull recent commits from the tracking remote branch is:

git pull origin BRANCH_NAME

BRANCH_NAME is the name of the branch to which pull function has to be done.

18. Pull request

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.

To create a pull request:

  1. Make your changes in the forked repository/new branch in the same repository
  2. Push the changes back to your repo
  3. Click the Compare & pull request button
  4. Click Create pull request to open a new pull request

19. Merge Pull request

Merge a pull request into the upstream branch when work is completed. Anyone with push access to the repository can complete the merge.
To merge a pull request:

  1. Under your repository name, click Pull requests.
  2. In the “Pull Requests” list, click the pull request you’d like to merge.
  3. Choose the merge options for your repository.
  4. If prompted, type a commit message, or accept the default message.
  5. Click Confirm merge.
  6. Optionally, delete the branch. This keeps the list of branches in your repository tidy.

    image

    Here is a funny video which shows the effect of merge XD :)

    IMAGE ALT TEXT HERE

    20. Fetch & Merge

    This is basically a feature given by github to update our forked repository with that of original one.
    When someone commits to original repo or some pull requests get accepted, those changes won’t be reflected to forked copy.
    So in order to do so we can simply click that “fetch-upstream” button and click “fetch and merge”.

    image

21. Github Pages

This is basically a free front end web hosting service provided by GitHub .
We can even add customised domain names to our websites.
This service can give a glance to clients on how our web based projects work.
Steps to host:

1. Push your code to GitHub using git commands from terminal

2. Go to repository settings of that repository and click “pages”.

image

image

3. In that source option change that from none to master(or the branch name which you want to delpoy).

image

4. Now save it and wait for few seconds.

5. Now we can see a url that gets popped up this will be the url of our public website.

image

Made with ❤️ TinkerHub MEC