DEV Community

Cover image for Git Command Cheat Sheet
anitaparmar26
anitaparmar26

Posted on • Edited on

Git Command Cheat Sheet

Hello Dev,

We all know about Git but I want to share little bit about that, In daily base where I am using, it is basic cheat sheet need to all developers.

Lots of code conflict had been when we were working in a team to completed project. That time we decided to have one cheat sheet on our office wall above desk.

Git Clone:

git clone https://name-of-the-repository-link
Enter fullscreen mode Exit fullscreen mode

Git New branch, list, deleting:

git branch -b (branch name)
git branch or git branch --list
git branch -d 
Enter fullscreen mode Exit fullscreen mode

Git Checkout:

git checkout (branch name)
Enter fullscreen mode Exit fullscreen mode

Git Switch:
git switch means you have already created branch.

git switch (branch name) 
Enter fullscreen mode Exit fullscreen mode

Git Status Command for:
like current branch, commit, push or pull, files staged, unstaged or untracked, files created, modified or deleted

git status
Enter fullscreen mode Exit fullscreen mode

Git Add:

git add 
git add -A (for everything)
Enter fullscreen mode Exit fullscreen mode

Git Commit:

git commit -m "commit message"
Enter fullscreen mode Exit fullscreen mode

Git Push: for upload local repo content

  1. git push: it is commonly used to upload local repository content to a remote repository.
  2. git push --set-upstream: Branch 'branch Name' set up to track remote branch 'branch Name' from 'origin'.
  3. git push -u origin: For push working existing branch .
git push 
git push --set-upstream 
git push -u origin
Enter fullscreen mode Exit fullscreen mode

Git Pull: for git fetch from local repo which will merge branch

git pull
Enter fullscreen mode Exit fullscreen mode

Git Merge: for merge branch to another

git checkout (branch name)
git fetch
git merge
Enter fullscreen mode Exit fullscreen mode

Thank you for reading.

Top comments (15)

Collapse
 
ezpzdevelopement profile image
Ez Pz Developement

Awesome, post you can also add git rebase , and git cherry-pick both of this command are useful.
check this two links if you want read more
git-scm.com/docs/git-cherry-pick
git-scm.com/docs/git-rebase

Collapse
 
anitaparmar26 profile image
anitaparmar26

Sure

Collapse
 
mbakog90210 profile image
mbakoG90210

One of the most frequent commands I have found myself using, especially for full stack app development, is git issues.Its a handy lil tool to know which when used with merge requests, helps add or edit app/web features to a project without the risk of messing up the main branch.

For CLI use, we have the following commands

Create a new issue
gh issue create [flags]

Options
-a, --assignee
Assign people by their login. Use "@me" to self-assign.
-b, --body
Supply a body. Will prompt for one otherwise.
-F, --body-file
Read body text from file (use "-" to read from standard input)
-l, --label
Add labels by name
-m, --milestone
Add the issue to a milestone by name
-p, --project
Add the issue to projects by name
--recover
Recover input from a failed run of create
-t, --title
Supply a title. Will prompt for one otherwise.
-w, --web
Open the browser to create an issue
Options inherited from parent commands
-R, --repo <[HOST/]OWNER/REPO>

Collapse
 
anitaparmar26 profile image
anitaparmar26

Sure, I will add
Thanks,

Collapse
 
sr_bala_kkl profile image
SR.Bala

Why there is 3 command for git push?
What is the difference between each of them.

Collapse
 
anitaparmar26 profile image
anitaparmar26 • Edited

As Answer there are same meaning all of three but both push just the remote repository, but it's when you pull that you notice the difference.

Thank You.

Collapse
 
sehgalspandan profile image
Spandan Sehgal

Very useful
Thanks for posting .
Keep it up !

Collapse
 
anitaparmar26 profile image
anitaparmar26

Thank you

Collapse
 
sandip profile image
Sandip

Thanks for posting, really helpful !
Keep posting more like this one :)

Collapse
 
anitaparmar26 profile image
anitaparmar26

Sure

Thank you for reading

Collapse
 
arpanforgeek profile image
Arpan Bandyopadhyay

Very useful .

Wanted to add one more :

** Create new branch & switch to that branch
git checkout -b (branch-name)

rebase is also very useful to us as a developers :)

Collapse
 
anitaparmar26 profile image
anitaparmar26

Sure, I will add
Thanks you

Collapse
 
hazhar_maroufi profile image
hazhar maroufi

Git commit must be closed β€œ missing

Collapse
 
anitaparmar26 profile image
anitaparmar26

Yes absolutely right, Thanks

Collapse
 
susankater profile image
SusanKater

How to replace the last commit with a combination of the staged changes? top & best indian astrologer in canada