DEV Community

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

Posted 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>
Enter fullscreen mode Exit fullscreen mode

followed with:

--global user.name "FirstName LastName"
--global user.name "yourEmail@email.com"
--global color.ui true
--list
Enter fullscreen mode Exit fullscreen mode

Git: starting a repository

git init
git status
Enter fullscreen mode Exit fullscreen mode

Git: staging files

adding files to staging area

git add <fileName>
git add <fileName> <anotherFileName>
git add .
git add --all
git add -A
Enter fullscreen mode Exit fullscreen mode

removes a file from the staging area

git rm --cached <fileName>
Enter fullscreen mode Exit fullscreen mode

discard change or reset the file

git reset <fileName>
Enter fullscreen mode Exit fullscreen mode

Git: committing to a repository

Appendix:

-m → stands for a message

git commit -m "Add three files"

Enter fullscreen mode Exit fullscreen mode

undo the last Git commit

git reset --soft HEAD^
Enter fullscreen mode Exit fullscreen mode

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 
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)