đź‘‹ Welcome
A.A.

Version Control | Git & GitHub

“Control the changes at every stage of your coding journey”

Photo by Praveen Thirumurugan on Unsplash

Problem

Consider a scenario where you made some extensive modifications and submitted it to to team for evaluation, Now team comes up with the issue and asks you to rollback all the changes… well this is a tough task because these changes are not isolated to one file.

Now how will you correct this without affecting other functionality

what if you don’t have a backup copy of that file… 🥴… Tough task right.!!!

Solution.

This is where version control, particularly with Git and GitHub, becomes your coding superhero.

Why Git/GitHub

  • Free & OpenSource
  • Complete Package ( git will cover local development and GitHub will cover online maintenance and collaboration)
  • Future-Proofing Your Projects:

In this, we store a record for every change with the help of certain tools like Git/GitHub… Well this tool provides much more functionality respectively

Working with Git / GitHub

To use git in the local system we need a command line tool called “git bash”

  • Install Git Bash: link

To store files on online server, we need to create an account on GitHub

Git Terminology

  • git: an open-source, distributed version control system
  • GitHub: a platform for hosting and collaborating on Git repositories
  • commit: a Git object, a snapshot of your entire repository compressed into a SHA
  • branch: a lightweight movable pointer to a commit
  • clone: a local version of a repository, including all commits and branches
  • remote: a common repository on GitHub that all team member use to exchange their changes
  • fork: a copy of a repository on GitHub owned by a different user pull
  • request: a place to compare and discuss the differences introduced on a branch with reviews, comments, integrated tests, and more
  • HEAD: representing your current working directory, the HEAD pointer can be moved to different branches, tags, or commits when using git checkout

Important Git command

Configuration

Configure user information for all local repositories

git config --global user.name "[name]"  
// Sets the name you want attached to your commit transactions  
  
git config --global user.email "[email address]"  
// Sets the email you want attached to your commit transactions  
  
[Note]: to configur it for a particular repo, remove '--global' flag from above command

Create repositories

  
git init  
// Turn an existing directory into a git repository  
  
git clone [url]  
// Clone (download) a repository that already exists on  
GitHub, including all of the files, branches, and commits

Branches

git branch [branch-name]  
// Creates a new branch  
  
git checkout [branch-name]  
// Switches to the specified branch and updates the  
working directory  
  
git merge [branch]  
// Combines the specified branch’s history into the  
current branch. This is usually done in pull requests,  
but is an important Git operation.  
  
git branch -d [branch-name]  
// Deletes the specified branch

Make changes in any specific branch code.

  
git log  
// Lists version/change/commi history for the current branch  
  
git diff [first-branch]...[second-branch]  
// Shows content differences between two branches  
  
git show [commit]  
// Outputs metadata and content changes of the specified commit  
// we get commits hash code in log   
  
git add [file]  
// move a particular file to staging area, So that we can commit those files  
// files which have any modification  
  
git ass .   
// move all file to staging area  
  
git commit -m "[descriptive message]"  
// Records file snapshots permanently in version history

Revert/rollback changes

  
git reset [commit]  
// Undoes all commits after [commit], preserving changes locally  
// use git log to get commit hash  
  
git reset --hard [commit]  
// Discards all history and changes back to the specified commit

Update the changes to GitHub

  • create a repository on GitHub and add its URL to the remote address
  • pull any change, that is there on the GitHub repository but not locally (i.e: ReadMe file)
  • push all files to GitHub
git remote add origin "repo_url"  
// origin is just a reference name ; it could be anything  
  
git pull origin <branch_name>  
// branch name could be master/main for new repo.  
  
git push origin <branch_name>  
// update changes in local file to github repository

User Story

…any suggestions? 👨‍🎓do comment

Git Resources: