Bash

Git Cheat Sheet

Find Useful Git commands in this Git Cheat Sheet.

Here is a basic Git cheat sheet:

git init – Initialize a new git repository

git clone [repository] – Clone an existing repository

git status – Check the status of your repository

git add [file] – Add a file to the repository

git commit -m "[message]" – Commit changes with a message

git push – Push changes to a remote repository

git pull – Pull changes from a remote repository

git branch – Show the current branch

git branch [branch-name] – Create a new branch

git checkout [branch-name] – Switch to a different branch

git merge [branch-name] – Merge a branch into the current branch

git log – Show the commit history

git diff – Show changes between commits

git reset --hard [commit] – Reset repository to a specific commit

git stash – Stash changes

git stash apply – Apply stashed changes

Please note that this is a basic cheat sheet and git has many more functionalities and options, it is worth reading the git documentation to learn more.

  • Clone a project:
    git clone git_repo_url project_name
  • Switch to a branch locally:
    git checkout branch_name
  • Modify a file, then save and push it to remote repo in current branch
    git add path_to_file_modifeid/file_name
    git commit -m “Description of modification”
    git push
  • Get a new version of a file after modifying local version
    git checkout path_to_file_modified/file_modified
  • Get latest version of current branch
    git fetch
    git pull
    if you have local changes, you will be prompted to commit or stash them before pulling.
  • Create a new branch based on current branch and switch to it
    git checkout –b branch_name
  • Switch to master branch
    git checkout master
  • Merge branch_name to master
    git merge branch_name
  • Delete local branch
    git branch -d branch_name
  • Undo a merge or pull
    git reset –hard
  • Undo a commit locally and on the remote branch
    git reset –hard commit_id
    git push –force
  • Get remote url of a local branch
    git remote show origin

Source: https://git-scm.com

Etienne Noumen

Sports Lover, Linux guru, Engineer, Entrepreneur & Family Man.

Recent Posts

The Importance of Giving Constructive Feedback

Offering employees, coworkers, teammates, and students constructive feedback is a vital part of growth on…

4 days ago

Why Millennials Need To Invest for Retirement Now

Millennials should avoid delaying the inevitable and look into various retirement investment pathways. Here’s why…

4 days ago

A Daily Chronicle of AI Innovations in May 2024

AI Innovations in May 2024

1 week ago

Tips for Ensuring Success Throughout Your Career

For most people, a satisfactory career is essential for leading a happy life. However, ensuring…

2 weeks ago

Different Career Paths in the Pipeline Industry

The pipeline industry is more than pipework and construction, and we explore those details in…

2 weeks ago

SQL Interview Questions and Answers

SQL Interview Questions and Answers In the world of data-driven decision-making, SQL (Structured Query Language)…

3 weeks ago