13 Git Commands Every Developer Must Know

1. Git Init

$ git init

2. Git Clone

$ git clone <https://url-of-the-repository>
$ git remote rm origin

3. Git Branch

$ git branch <branch-name>
$ git branch
$ git branch --list
$ git branch -d <branch-name>

4. Git Checkout

$ git checkout <branch-name>
  • If you made some changes in the previous branch, you will have to first commit and push them (I’ll cover this command below) to your remote repository.
  • The branch you want to switch must be present in your local system. If not, you can pull them (covered below).
$ git checkout -b <branch-name>

5. Git Add

$ git add <file-name>
$ git add -A

6. Git Commit

$ git commit -a
$ git commit -am "<commit-message>"

7. Git Push

$ git push <remote> <branch-name>

8. Git Pull

$ git pull <remote>

9. Git Diff

$ git diff
$ git diff branch1..branch2
$ git diff branch1 branch2 ./path/to/file.txt

10. Git Stash

$ git stash save "<stash-message>"
$ git stash save -u
$ git stash list
stash@{0}: On master: Stashed with message1 
stash@{1}: On master: Stashed with message2
$ git stash apply

11. Git Status

$ git status
  • Your current branch
  • Whether your current branch is up to date
  • If there’s anything in the branch that needs to be committed, pushed, or pulled.
  • If you have any files that are either staged or not staged.
  • And if you have any files that are created, modified, or deleted.

12. Git Log

$ git log
  • If you want to view only the last 3 commit history, you can use the following command: git log -n 3.
  • To condense the commit history into a single line and view them, run git log --oneline. This is the easiest way to get a high level overview of all the commit history. It might still be a bit too much if you've got a lot of commits.
  • If you want to view the commit history by a specific author, run git log --author"<author-username>".

13. Git Merge

$ git checkout develop
$ git pull
$ git merge feature1

Streamline your Development Workflow

Git Workflow Automation in Zepel
Automating developer workflow with Zepel

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store