DEV Community

Cover image for A Git cheat sheet – $get git
Anuvindh for AWS Community Builders

Posted on • Edited on • Originally published at ictpro.co.nz

A Git cheat sheet – $get git

DAY 29 - A Git cheat sheet – $get git - Day Twenty Nine

Image tweet
100 days of Cloud on GitHub - Read On iCTPro.co.nz - Read on Dev.to


Git Commands Comes handy

Git is a highly matured open-source software that is famous for tracking changes and collaboration among programmers. Git plays a major role in DevOPS for source code management.

The git is very efficient in speed, data integrity, and support for distributed, non-linear workflows

Basic Git commands

  • Clone a repository
git clone [url]
Enter fullscreen mode Exit fullscreen mode
  • Start a new repository
git init [repository]
Enter fullscreen mode Exit fullscreen mode
  • Add file to the staging area
git add [filename]
Enter fullscreen mode Exit fullscreen mode
  • Save changes to repository & commit
git add .
git commit -m " my first commit"
Enter fullscreen mode Exit fullscreen mode
  • Status of repository
git status 
Enter fullscreen mode Exit fullscreen mode
  • Show difference which you are not staged
git log
Enter fullscreen mode Exit fullscreen mode
  • Differences between the two branches – branch_1 and branch_2
git diff branch_1 branch_2
Enter fullscreen mode Exit fullscreen mode
  • Get the entire commit history
git diff branch_1 branch_2 
Enter fullscreen mode Exit fullscreen mode

Git Undo

  • Undo the previous commit
git revert HEAD^ 
Enter fullscreen mode Exit fullscreen mode
  • Revoke from the staging area but leave the working directory unchanged
git reset [file] 
Enter fullscreen mode Exit fullscreen mode
  • Shows which files be removed from the working directory
git clean -n 
Enter fullscreen mode Exit fullscreen mode

Git Branches

  • List all branchs
git branch
Enter fullscreen mode Exit fullscreen mode
  • Create new branch
git branch [NameOfBranch]
Enter fullscreen mode Exit fullscreen mode
  • List all branches
git branch -a
Enter fullscreen mode Exit fullscreen mode
  • Deleting a branch
git branch -d [NameOfBranch]
Enter fullscreen mode Exit fullscreen mode
  • Merging all changes to current branch
git merge [NameOfBranch]
Enter fullscreen mode Exit fullscreen mode
  • Checking an existing branch
git checkout [NameOfBranch]
Enter fullscreen mode Exit fullscreen mode

Git Tag

  • Creating a tag
git tag [TagName]
Enter fullscreen mode Exit fullscreen mode
  • Deleting a tag
git tag -d [TagName] 
Enter fullscreen mode Exit fullscreen mode
  • Push tags
git push --tags
Enter fullscreen mode Exit fullscreen mode

Git Remote repositories

  • Getting latest version of the repository
git pull[NameOfBranch] [url]
Enter fullscreen mode Exit fullscreen mode
  • Gets a specific [branch] from the repo
git fetch [remote_url] [branch] 
Enter fullscreen mode Exit fullscreen mode
  • Get speficif remote copy of branch
git pull [remote_url]
Enter fullscreen mode Exit fullscreen mode
  • Push branch to remote
git push [remote_url] [BrnaceName]
Enter fullscreen mode Exit fullscreen mode

Git Delete

  • Deleting file – Force
git rm -f [NameOfFile]
Enter fullscreen mode Exit fullscreen mode
  • Remove the entire Directory from the working index
git rem -r --cached [NameofDirecotry]
Enter fullscreen mode Exit fullscreen mode
  • Deleting an entire directory
git rm -r -f [NameofFile]
Enter fullscreen mode Exit fullscreen mode

✅Connect with me on Twitter
🤝🏽Connect with me on Linkedin
🧑🏼‍🤝‍🧑🏻 Read more post on dev.to or iCTPro.co.nz
💻 Connect with me on GitHub


Top comments (2)

Collapse
 
w3ndo profile image
Patrick Wendo

What does a tag do specifically?

Collapse
 
anuvindhs profile image
Anuvindh

Tag is name that points to commit, in other words Tags helps to navigate to a specific point of your repo.

Let’s say you wanna give a release using tag you can name the release or tag the release like v0.1 or v1.2.

The use case is mainly to restore your data to a specific point on your commit .