DEV Community

loading...

You Must use these Git cmds

Sanjay Singh Rajpoot
πŸ‘¨β€πŸ’»β–ͺ️ Full Stack Developer (MERN) | Tech Blogger | C++ Guy | B.tech ECE | πŸ™‹β€β™‚οΈLearner
・2 min read

Git is important to use for all of us as a web developer or a software developer. Git is the most widely used and powerful version control system for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for source code management in software development, but it can be used to keep track of changes in any set of files.

They would be super useful for accomplishing common tasks like creating or renaming a git branch, removing files, and undoing changes. While other version control systems e.g. CVS, SVN keeps most of their data like commit logs on a central server, every git repository on every computer is a full-fledged repository with complete history and full version tracking abilities, independent of network access or a central server.

However, almost all IDEs support git out of the box and we do not require submitting the git commands manually but it is always good to understand these commands. Below is a list of some git commands to work efficiently with git.

Here are the list of git commands that I most commonly use

  • git init : Initialize a local Git repository
  • git clone repo_url : Clone public repository
  • git clone ssh://git@github.com/[username]/[repository-name].git : Clone private repository
  • git status: Check status
  • git add [file-name] : Add a file to the staging area
  • git add -A : Add all new and changed files to the staging area
  • git commit -m β€œ[commit message]” : Commit changes
  • git rm -r [file-name.txt] : Remove a file (or folder)
  • git branch : List of branches (the asterisk denotes the current branch)
  • git branch -a : List all branches (local and remote)
  • git branch [branch name] : Create a new branch
  • git checkout -b [branch name]: Create a new branch and switch to it
  • git merge [branch name]: Merge a branch into the active branch
  • git merge [source branch] [target branch]: Merge a branch into a target branch
  • git push: Push changes to remote repository (remembered branch)
  • git push origin β€” delete [branch name] : Delete a remote branch
  • git pull : Update local repository to the newest commit
  • git pull origin [branch name]: Pull changes from remote repository
  • git remote add origin ssh://git@github.com/[username]/[repository-name].git: Add a remote repository
  • git log: View changes
  • git config β€” global user.name β€œyour_username”: Set globally Username

Thanks for scrolling.

Discussion (3)

Collapse
jmfayard profile image
Jean-Michel Fayard πŸ‡«πŸ‡·πŸ‡©πŸ‡ͺπŸ‡¬πŸ‡§πŸ‡ͺπŸ‡ΈπŸ‡¨πŸ‡΄ • Edited

I'm not sure that it's true that we "must" use those git commands.
What is important is to learn the concepts, not the commands

The command-line interface is just one interface to git, and a very poor one IMHO.

When my project is open in IntelliJ, I can do all of this with a non-crappy user interface.

When I am in a terminal and want to do quickly git operations, I am using lazygit

GitHub logo jesseduffield / lazygit

simple terminal UI for git commands

CI Go Report Card GolangCI GoDoc GitHub tag TODOs

A simple terminal UI for git commands, written in Go with the gocui library.

Rant time: You've heard it before, git is powerful, but what good is that power when everything is so damn hard to do? Interactive rebasing requires you to edit a goddamn TODO file in your editor? Are you kidding me? To stage part of a file you need to use a command line program to step through each hunk and if a hunk can't be split down any further but contains code you don't want to stage, you have to edit an arcane patch file by hand? Are you KIDDING me?! Sometimes you get asked to stash your changes when switching branches only to realise that after you switch and unstash that there weren't even any conflicts and it would have been fine to just checkout the branch directly? YOU HAVE GOT TO BE…




Collapse
extrawurst profile image
Stephan Dilly • Edited

Or you use a tool with a little more comfort: github.com/extrawurst/gitui :P
demo

Collapse
sanjaysinghrajpoot profile image
Sanjay Singh Rajpoot Author

Wow that's really good