Git & Github

Git & Github

INTRODUCTION

Today, we're diving into the world of Git and GitHub, two essential tools for modern software development and collaboration.Git is distributed version control system It allows you to collaborate with others and maintain a history of your project's development.With Git, you can create, modify, and merge code seamlessly, all while keeping a detailed record of every change. This makes it easier to work on projects with others, identify and fix issues, and even roll back to previous versions if something goes wrong.

🤝 Collaborate effectively: Multiple developers can work on the same project simultaneously without stepping on each other's toes.

🔍 Track changes: You can see who made what changes and when, making it easier to identify and fix issues.

⏪ Rollback to previous versions: If something goes wrong, you can revert to a previous working version of your code.

GIT stages and it's terminology:

Repository: Repo is a place where you name all your codes or kind of folder on server.It is a kind of folder related to one product.Changes are personal to that perticular repository.

Server:

  • It is store all repository. It is store all repository.

Working Directory:

  • Where you see files physically and do modification.At a time you can work on perticular branch.
  • In other cvcs(centralized version control system), developers generally makes modification and commit there changes directly to the repository, but git uses a different strategy. Git doesnot track each and every modified file whenever you do commit an operations.

  • Git looks for the files present in the staging area only those files present in the staging area are considered for commit and not all the modified files.

Working directory

Add

Staging area

commit

Local repository

Push to GitHub

Commit:

  • Store changes in repository you will get once commit -ID.

  • It is 40 alpha-neumeric character.

  • It is uses SHA-1 checksum.

  • Even if you change one dot, commit ID will get change.

  • It is actually helps to track the changes.

  • Commit also named as SHA-1 hash.

    Tags:

  • Tags assign a meaningful name with a specific version in the repo, once a tag is created for a particular save, even if you create a new commit it will not be updated.

Snapshots:

  • Represents some data of particular time.

  • It is always incremental i.e it stores the changes (appended data) only not entire copy.

Push:

  • Push operations copies changes from a local repo instances to a remoteor central repo.this is used to store the changes permanently into the git repo.

Pull:

  • Pull operations copies the changes from a remote repositories to a local machines. The pull operations is used for synchronization between two repo.

    branches:

  • Product is same, so one repo but different task.

  • Each task has one separate branch.

  • Finally merges (code) all the branches.

  • Useful when you want to work.

  • Can create one branch on the basis of another branch.

  • Changes are personal to that particular branch.

  • Default branch is “master branch”.

  • File created in working space will be visible in any of the branch work space until you commit one you commit then that file belongs to that particular branches.

Advance of GIT

  • Free and open source.

  • Fast and smalls as most of the operations are performed locally, there for it is fast.

Security:

  • Git uses a common cryptographic hash function. (SHA-1) to name and identify objects within its database.

  • No need of powerful hardware.

  • Easier branching if we create a new branch it will copy all the code to new branch.

    How to commit,push and pull from github?

  • Create one directory

  • cd “directory”

  • git init

  • touch “filename”

  • git status

  • git add .

  • git commit -m “any msg”

  • Connect with Github
  • git remote add origin (github url)

  • git push -v origin master

How to pull from github?

  • git clone (github repo url)

  • git pull (github repo url)

    Git conflict:

  • When same file having a different branches, if you do merge conflict occurs resolve conflict then add and commit.

  • Conflict occurs when you merge branches.

    Git stashing:

  • Suppose you are implementing a new feature for your product your code is in progress and suddenly a customer escalation comes because of this you have to keep a side your new feature work for few hours. You cannot commit your partial code and also cannot throw away your changes so you need some temporary storage , when you can store your partial change and later commit it.

  • To stash an item (only applied to modified files not new file).

    Git reset:

  • Git reset is a powerful command that is used to undo local changes to the state of git repo.

To reset staging area

  • git reset (filename)

  • git reset .

  • To reset the changes from both staging area and working directory at a same time.

  • git reset --hard

    Git revert:

  • The revert command helps you undo on existing commit

  • It does not delete any data in this process instead rather git creates a new commit with the include files reverted to their previous state so, your version control history moves forwarded while the state of your file moves backward.

thank you for reading.