Git  CheatSheet

Git CheatSheet

The World of software engineering is so dynamic, a software that was built can have an upgraded version after several months thereby creating room for improvement and introduction of fresh ideas in product development. One innovation in the software engineering world that has changed how software developers operate is the introduction of VCS (version control system).


What is VCS (version control system) ?
Version control, also known as source control, is the practice of tracking and managing changes to software code. Version control systems are software tools that help software teams manage changes to source code over time.
Let's assume John is a software developer and is building a social media app for company A, after building to point X, he had a meeting with company A and showed them the progress of the job which company A was cool with but ask him to add some buttons and twik the app color a little bit to make it look better. In three days' time, after making the corrections and building the app to point Y company A and John had a meeting, during the project review company A express their displeasure over the present appearance of the app even though progress was great, the corrections and update did at point X have messed up the look of the project, they rather prefer the app appearance return to point X while the project is at point Y. The task of returning the project back to point X and rebuilding it to point Y is quite hectic and will cost time which definitely will delay the delivery date of the job. Several developers have been in this state once or several times in their carrier and can tell you the pain they went through.
why version control system? Version control software keeps track of every modification to the code in a special kind of database. If a mistake is made, developers can turn back the clock and compare earlier versions of the code to help fix the mistake while minimizing disruption. Git
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. Use of Git

  • Git is used to track changes in the source code.
  • Source code management
  • It allows multiple developers to work together via GitHub
  • It supports non-linear development through its thousands of parallel branches

Basic Git Cheatsheet

Git Setup

Configuring user information used across all repository


Set user name and email address


git config --global user.name "[firstname othername]" 

git config --global user.email "[email address]"

Create an empty Git repository or reinitialize an existing one


Initializing repository


git init

Add file as it's ready for your next commit (stage)

Add single file to staging area


git add <filename>

Add all file to staging area


git add .

Remove file

Remove files staging area


git rm <filename>

Add all file to staging area


git add .

Show modified files in working directory, staged for your next commit

Status of file

git status

commit your staged content as a new commit snapshot

Record changes to the repository

git commit -m "[message description]"

diff of what is changed

diff of what is change but not stage

git diff

diff of staged but not commited file

git diff --staged

Grow, mark and tweak your common history

  • Branch
    Create new branch
    git branch <branch name>
    
    List branch
    git branch
    
    Switch to another branch
    git checkout <branch name>
    
    Switch to another branch
    git switch <branch name>
    
    Create and check out a new branch
    git checkout -b <branch name>
    
    Rename branch
    git mv
    

To learn more git command