Git

  Git is distributed version control system which is free and open source software (FOSS). It is a tool to track the changes in the code. We save an initial version of code in the git and then update over the time. We can look back all the changes done so far. Github is the website to host the repositories online.

Once we have made changes local repository on the computer and ready to put in git, we need to tell git to track them through add command, save file through commit command and then upload the changes to remote repository using push command. Thus we can keep track the version history and also isolate the changes.

SSH (Secure SHell protocol is used for authentication and it is secure and convenient way to log into remote servers) keys need to be generated which consists of pair of keys, private and public keys. Public key is shared with the world via GitHub while the private key is kept secured on one's computer. When we try to connect with GitHub, SSH client provides private key to prove who you are. The GitHub then verifies with the corresponding public key. 

Work Flow



            

Git Branching

Master Branch : The main branch (often named main or master) represents the stable and production-ready version of the code. Feature branches are created and merged into the main branch once the new features are thoroughly tested and approved.

Feature Branch: A feature branch is created to work on a specific feature or enhancement. It allows developers to isolate their work from the main codebase until the feature is complete and ready for review.

Hotfix Branch: A hotfix branch is created to address critical issues or bugs in the production code. It allows developers to make urgent fixes without disrupting ongoing development in feature branches.

Uses

It enables tracking changes in files over time, providing developers with a comprehensive history of revisions. This decentralised approach allows for collaboration among multiple developers, facilitating simultaneous work on different aspects of a project.

One of its key features is branching and merging, which supports parallel development by allowing developers to work on separate branches of code and later integrate their changes seamlessly. This promotes an efficient and organized workflow, essential for large-scale projects.

Git ensures data integrity and backup through its robust system, minimizing the risk of data loss or corruption. Its flexible workflow, powered by various commands, offers developers the freedom to customize their working environment to suit their specific needs and preferences.

Each change made to the codebase is recorded through commits, accompanied by meaningful messages that provide context and clarity about the modifications.

Git also excels in its search functionality, enabling developers to efficiently navigate through the project's history and revert to previous versions if needed.

Additionally, Git supports hosting on various platforms like GitHub, GitLab, and Bitbucket, making it accessible and adaptable to different hosting environments.

Git revolutionises version control in software development, empowering teams to collaborate effectively, manage code changes seamlessly, and maintain a high level of productivity throughout the development lifecycle.


Git Commands

ssh-keygen -t rsa -b 4096 -C "your_email@example.com": Generate SSH key
Fork - You start by forking a repository on GitHub. This creates your own copy of someone else's repository.
git init: initialise a new Git repository in your project directory
๐—ด๐—ถ๐˜ ๐—ฑ๐—ถ๐—ณ๐—ณ: Show file differences not yet staged.
๐—ด๐—ถ๐˜ ๐—ฐ๐—ผ๐—บ๐—บ๐—ถ๐˜ -๐—ฎ -๐—บ "๐—ฐ๐—ผ๐—บ๐—บ๐—ถ๐˜ ๐—บ๐—ฒ๐˜€๐˜€๐—ฎ๐—ด๐—ฒ": Commit all tracked changes with a message.
๐—ด๐—ถ๐˜ ๐˜€๐˜๐—ฎ๐˜๐˜‚๐˜€: Show the state of your working directory.
๐—ด๐—ถ๐˜ ๐—ฎ๐—ฑ๐—ฑ ๐—ณ๐—ถ๐—น๐—ฒ_๐—ฝ๐—ฎ๐˜๐—ต:Add file(s) to the staging area.
๐—ด๐—ถ๐˜ ๐—ฐ๐—ต๐—ฒ๐—ฐ๐—ธ๐—ผ๐˜‚๐˜ -๐—ฏ ๐—ฏ๐—ฟ๐—ฎ๐—ป๐—ฐ๐—ต_๐—ป๐—ฎ๐—บ๐—ฒ: Create and switch to a new branch.
๐—ด๐—ถ๐˜ ๐—ฐ๐—ต๐—ฒ๐—ฐ๐—ธ๐—ผ๐˜‚๐˜ ๐—ฏ๐—ฟ๐—ฎ๐—ป๐—ฐ๐—ต_๐—ป๐—ฎ๐—บ๐—ฒ: Switch to an existing branch.
๐—ด๐—ถ๐˜ ๐—ฐ๐—ผ๐—บ๐—บ๐—ถ๐˜ --๐—ฎ๐—บ๐—ฒ๐—ป๐—ฑ:Modify the last commit.
๐—ด๐—ถ๐˜ ๐—ฝ๐˜‚๐˜€๐—ต ๐—ผ๐—ฟ๐—ถ๐—ด๐—ถ๐—ป ๐—ฏ๐—ฟ๐—ฎ๐—ป๐—ฐ๐—ต_๐—ป๐—ฎ๐—บ๐—ฒ: Push a branch to a remote.
๐—ด๐—ถ๐˜ ๐—ฝ๐˜‚๐—น๐—น: Fetch and merge remote changes.
๐—ด๐—ถ๐˜ ๐—ฟ๐—ฒ๐—ฏ๐—ฎ๐˜€๐—ฒ -๐—ถ: Rebase interactively, rewrite commit history.
๐—ด๐—ถ๐˜ ๐—ฐ๐—น๐—ผ๐—ป๐—ฒ: Create a local copy of a remote repo.
๐—ด๐—ถ๐˜ ๐—บ๐—ฒ๐—ฟ๐—ด๐—ฒ: Merge branches together.
๐—ด๐—ถ๐˜ ๐—น๐—ผ๐—ด --๐˜€๐˜๐—ฎ๐˜: Show commit logs with stats.
๐—ด๐—ถ๐˜ ๐˜€๐˜๐—ฎ๐˜€๐—ต: Stash changes for later.
๐—ด๐—ถ๐˜ ๐˜€๐˜๐—ฎ๐˜€๐—ต ๐—ฝ๐—ผ๐—ฝ: Apply and remove stashed changes.
๐—ด๐—ถ๐˜ ๐˜€๐—ต๐—ผ๐˜„ ๐—ฐ๐—ผ๐—บ๐—บ๐—ถ๐˜_๐—ถ๐—ฑ: Show details about a commit.
๐—ด๐—ถ๐˜ ๐—ฟ๐—ฒ๐˜€๐—ฒ๐˜ ๐—›๐—˜๐—”๐——~๐Ÿญ or 
git reset "commit #code" (obtained from log): Undo the last commit, preserving changes locally.
๐—ด๐—ถ๐˜ ๐—ณ๐—ผ๐—ฟ๐—บ๐—ฎ๐˜-๐—ฝ๐—ฎ๐˜๐—ฐ๐—ต -๐Ÿญ ๐—ฐ๐—ผ๐—บ๐—บ๐—ถ๐˜_๐—ถ๐—ฑ: Create a patch file for a specific commit.
๐—ด๐—ถ๐˜ ๐—ฎ๐—ฝ๐—ฝ๐—น๐˜† ๐—ฝ๐—ฎ๐˜๐—ฐ๐—ต_๐—ณ๐—ถ๐—น๐—ฒ_๐—ป๐—ฎ๐—บ๐—ฒ: Apply changes from a patch file.
๐—ด๐—ถ๐˜ ๐—ฏ๐—ฟ๐—ฎ๐—ป๐—ฐ๐—ต -๐—— ๐—ฏ๐—ฟ๐—ฎ๐—ป๐—ฐ๐—ต_๐—ป๐—ฎ๐—บ๐—ฒ: Delete a branch forcefully.
๐—ด๐—ถ๐˜ ๐—ฟ๐—ฒ๐˜€๐—ฒ๐˜: Undo commits by moving branch reference.
๐—ด๐—ถ๐˜ ๐—ฟ๐—ฒ๐˜ƒ๐—ฒ๐—ฟ๐˜: Undo commits by creating a new commit.
๐—ด๐—ถ๐˜ ๐—ฐ๐—ต๐—ฒ๐—ฟ๐—ฟ๐˜†-๐—ฝ๐—ถ๐—ฐ๐—ธ ๐—ฐ๐—ผ๐—บ๐—บ๐—ถ๐˜_๐—ถ๐—ฑ: Apply changes from a specific commit.
๐—ด๐—ถ๐˜ ๐—ฏ๐—ฟ๐—ฎ๐—ป๐—ฐ๐—ต: Lists branches.
๐—ด๐—ถ๐˜ ๐—ฟ๐—ฒ๐˜€๐—ฒ๐˜ --๐—ต๐—ฎ๐—ฟ๐—ฑ: Resets everything to a previous commit, erasing all uncommitted changes.
git stash clear or git stash drop stash@{1}: drop a stash
git stash apply or git stash apply stash@{2}: Apply stashed changes
git stash list: Show the stashes
git restore --staged <STEP3/output>: undo staged file











          
      


  1. git checkout branch-name


Comments

Popular posts from this blog

Transform values with a stream

Collections Framework

Inspect a collection