DEV Community

Cover image for Git Basic Commands
Muhammad Ridho Anshory
Muhammad Ridho Anshory

Posted on Edited on

Git Basic Commands

About this article

In this article, I will share with you guys what are the basic commands when using git CLI.

I know who did what, when, and why. -Git

Table of Contents

  1. Git: configurations
  2. Git: starting a repository
  3. Git: staging files
  4. Git: committing to a repository
  5. Git: pulling and pushing from and to repositories
  6. Git: branching

Git: configurations

git config <followed with>
🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน 🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน

followed with:

--global user.name "FirstName LastName"
--global user.name "yourEmail@email.com"
--global color.ui true
--list
🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน 🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน

Git: starting a repository

git init
git status
🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน 🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน

Git: staging files

adding files to staging area

git add <fileName>
git add <fileName> <anotherFileName>
git add .
git add --all
git add -A
🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน 🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน

removes a file from the staging area

git rm --cached <fileName>
🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน 🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน

discard change or reset the file

git reset <fileName>
🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน 🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน

Git: committing to a repository

Appendix:

-m → stands for a message

git commit -m "Add three files"

🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน 🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน

undo the last Git commit

git reset --soft HEAD^
🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน 🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน

Git: pulling and pushing from and to repositories

Appendix:

-u → add upstream (tracking) reference

git remote add origin <link> //Adding a remote repository
git push -u origin master //pushes all your branches to the origin.
git clone <cloneURL> // clone a repository
git pull // download all the changes 
🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน 🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน

Git: branching

git branch // current branch
git branch <branchName> // create a branch
git checkout <branchName> // change current branch
git merge <branchName> // merge branchName to current branch
git checkout -b <branchName> // create and checkout a new branch
🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน 🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน

If you guys have other thoughts leave a comment I'll update the post base on your solutions as well.. cheers🍻

Top comments (1)

🔴 Hot News: ridhoanshory/git basic commands ee - ประเด็นร้อน
 
aerabi profile image
Mohammad-Ali A'RÂBI •

Awesome cheat sheet. I would use the more modern git switch <branchName> instead of the checkout command that you mentioned.