Master Git Commands with This Handy Cheat Sheet 📜
Angel Oduro-Temeng Twumasi

Angel Oduro-Temeng Twumasi @angelotheman

About: Hey there! I'm here to simplify tech for you! Let's break down the jargon and get started on your projects together.

Location:
Accra, Ghana
Joined:
Nov 6, 2020

Master Git Commands with This Handy Cheat Sheet 📜

Publish Date: Jun 30 '23
13 6

Git, the widely used distributed version control system, has revolutionized the way developers collaborate and manage their codebases. Whether you're a seasoned developer or just starting your coding journey, having a solid understanding of essential Git commands is crucial for maintaining an efficient workflow and ensuring the integrity of your projects.

As said by Ben Collins-Sussman, Co-founder of Google Code 👇🏾

Git is a powerful tool for distributed version control. It is a way to ensure that your project evolves gracefully over time, no matter how many people are working on it.

Now steal this git cheat sheet I prepared for you 😀

🔗Configurations

  • Configure your name. This would serve as the author of the commit : git config --global user.name "[fistname lastname]"
  • Configure your email. This would serve as the email of the author : git config --global user.email "[your_email]"

🌱Initialization

  • Initialize a new Git repository : git init
  • Create a local copy of a remote repository : git clone <repository_url>
  • Add a remote repository : git remote add <remote_name> <remote_url>

📝Basic Workflow

  • Add a file to the staging area : git add <filename>
  • Add all files to the staging area : git add .
  • Commit changes to the repository : git commit -m "[commit_message]"

🔁Updating and Publishing

  • Publish all local commits to a remote branch : git push <remote_name> <branch_name>
  • Publish all local commits to a new branch : git push -u <remote_name> <branch_name>
  • Update the local repository : git pull
  • Download remote changes without merging : git fetch

🌿Branches

  • Create a new branch : git branch <branch_name>
  • Switch to a branch : git checkout <branch_name>
  • Create a new branch and switch to it : git checkout -b <branch_name>
  • List all the branches : git branch -a
  • Determine your current branch : git branch

🔀Merging

  • Combine changes of one branch to your current branch : git merge <branch_name>
  • Reapply commits on top of another base commit : git rebase <branch_name>

🔃Resets

  • Discard all local changes : git reset --hard HEAD

🔍Status and History

  • View the status of the working directory : git status
  • Show difference between commits or the working directory : git diff
  • Show commit history : git log
  • Display who last modified each line of a file : git blame

💼Additional commands

  • Remove untracked files : git clean -f

Useful tips ✍🏾

  • Don’t EVER commit private keys / Api keys / certificates.
  • Use descriptive commit messages and branch names.
  • Create a branch for every new feature, and delete the branch once the feature is merged into main.
  • Ignore some files using a .gitignore file.
  • Regularly update and sync with remote repositories
  • Use git alias for frequently used commands.

Visit Atlassian or GitHub Education to read more on other advanced git commands🔥

In conclusion, mastering Git commands is crucial for efficient version control and collaboration in software development, enabling developers to effectively manage projects and streamline workflows.

Did you learn anything new ❓ Share it in the comments.

Let's get interactive on Twitter and LinkedIn

Follow my projects on GitHub

Happy coding 👨🏾‍💻

Comments 6 total

  • Fred010
    Fred010Jun 30, 2023

    Good piece man. keep it up

  • Mardiya Zubairu
    Mardiya Zubairu Jul 2, 2023

    Great compilation👏
    One thing though..
    I think putting the commands in code blocks would help make them standout clearer between the texts
    Example👇

    Git command 
    
    Enter fullscreen mode Exit fullscreen mode

    Definitely keeping your cheat sheet Angel😅.

    • Angel Oduro-Temeng Twumasi
      Angel Oduro-Temeng TwumasiJul 2, 2023

      You gotta keep it yeah 😀.

      I'll look into your suggestion and update as best fit. Thank you so much. Really appreciate ❤️

  • Dimitri Mostrey
    Dimitri MostreyJul 3, 2023

    A suggestion: before using git clean -f you may want to run git clean -n as a dry-run and see what git will clean. If you want to include directories:
    git clean -d -f to force it
    git clean -d -n to have a preview peek to see what the command will actually delete (yes, this is not a typo)

    If you want some real fun, run git clean -d -x -f. It will also delete ignored files and directories. So please, don't run this on a production server. You will cry for your mama (who can't fix it for you 😝)

    Point being, be very careful with the git command clean.

    • Angel Oduro-Temeng Twumasi
      Angel Oduro-Temeng TwumasiJul 3, 2023

      What wonderful insights.

      Surely such precautions must be taken to ensure that such isn't done on the production server to cause any setbacks.

      Thank you 😍

Add comment