Skip to content

Instantly share code, notes, and snippets.

@sam43
Created November 3, 2021 03:33
Show Gist options
  • Save sam43/e83ab7838030a44b1c361d385f860a2b to your computer and use it in GitHub Desktop.
Save sam43/e83ab7838030a44b1c361d385f860a2b to your computer and use it in GitHub Desktop.
Git basic and important commands for use
# This command sets the author name and email address respectively to be used with your commits.
# command : 'git config'
Usage:
git config –global user.name “[name]”
git config –global user.email “[email address]”
# Initialize git
Usage:
git init [repository name]
# Git clone repository
Usage:
git clone [url]
# This command adds a file to the staging area
# command : 'git add'
Usage:
git add [file]
// to add all files
git add .
# This command records or snapshots the file permanently in the version history.
# command : 'git commit'
Usage:
git commit -m “[ Type in the commit message]”
// This command commits any files you’ve added with the git add command and also commits any files you’ve changed since then.
git commit -a
# This command shows the file differences which are not yet staged.
# command : 'git diff'
Usage:
git diff
// This command shows the differences between the files in the staging area and the latest version present.
git diff –staged
// This command shows the differences between the two branches mentioned.
git diff –staged [first branch] [second branch]
# command : 'git reset'
Usage:
git reset [file]
# This command unstages the file, but it preserves the file contents.
Usage:
git reset [commit]
# This command undoes all the commits after the specified commit and preserves the changes locally.
Usage:
git reset –hard [commit]
# This command discards all history and goes back to the specified commit.
# command : 'git rm' to delete files
# The files/folder in your version control will not just delete themselves just because you added them to the .gitignore. They are already in the repository and you have to remove them. You can just do that with this:
Usage:
// First commit then clear git caches
git rm -rf --cached .
// OR for specific file use- [Optional]
git rm --cached <filename>
// add changes to git
git add .
// commit the dhanges to git
git commit -m ".gitignore is now working"
@sam43
Copy link
Author

sam43 commented Nov 3, 2021

Find more of git commands here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment