Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SelfTaught-HamzaCodes/00e0a4a11ea77bb717b2221047d245b4 to your computer and use it in GitHub Desktop.
Save SelfTaught-HamzaCodes/00e0a4a11ea77bb717b2221047d245b4 to your computer and use it in GitHub Desktop.
Git | GitHub (Cheat Sheet for Beginners)
Git | GitHub (Cheat Sheet)
Created by: Muhammad Hamza Saeed
Downloading GIT
https://git-scm.com/downloads
Setting Credentials
- git config --global user.email <your email>
- git config --global user.email (to view your email)
- git config --global user.name <your usename>
- git config --global user.name (to view your username)
Initializing a Repository
- git init (while being inside a directory / folder)
- git clone <URL> <(optional) folder name>
Checking STATUS of our repository
- git status
- git status -s
(-s: summarized version, RED M represents - modified in the working directory
GREEN M represents - added to staging area)
ADD Files to Staging Area
- git add <name of file>
- git add . (all files in the directory)
- git add "*.txt" (only files with txt extension)
- git add <name of file 1> <name of file 2> ...
- git add -A (stages all files: untracked, modified even Deleted)
COMMIT our Files
- git commit <name of file>
- git commit -a (to commit all files within the working directory, that are currently staged)
- git commit -m "message that briefly tells about this commit"
- git commit -a -m "" (allows you to directly commit without staging)
REVERTING a Staged File / Recently Committed File to Previous Version
- git checkout <name of file> (Takes a staged file back to the last commited file)
- git restore <commit hash> -- <file name> (Takes a file to the commit mentioned within commit hash)
View LOG of your Commits
- git log (Author, Time & Message for all commits)
- git log -p (Details of what was done in each commit)
- git log -p -2 (Used to view last *2 commits, in details (-p))
Compare DIFFERENCES
- git diff (Compare, Working Tree with Staging Area)
- git diff --staged (Compare, Staging Area with last Commit)
REMOVING a File
- git rm <name of file> (Removes file from computer & staging area)
- git rm --cached <name of file> (Removes file from staging area only)
.GITIGNORE
- touch .gitignore (files name mentioned within this won't be committed / pushed)
Like Sir Harry said, avoid Temp, Bin Files, also avoid API Keys!
BRANCHES
- git branch <name of branch>
- git branch (to view all branches)
- git checkout <name of an existing branch> (to switch between branches)
- git checkout -b <name of branch> (Creates a new branch and takes you to that new branch)
- git merge <name of branch>
GITHUB
- git remote add origin <url>
- git remote
- git remote -v (show name of our remotre repository, with URL)
- git remote set-url origin <SSH Url>
- git push -u origin master (Establishes an upstream, allowing to push/pull without additional arguments)
SSH KEY SETUP
Step 1: $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Step 2: $ eval "$(ssh-agent -s)"
Step 3: $ ssh-add ~/.ssh/<name of your private key>
Step 4: (on terminal) -> cat ~/.ssh/<name of your public key (.pub)>
Step 5: Copy key (that ends with your email) and add within Git Hub!
Additional Commands
- touch <name of file.with extension> (To create files)
- ls - lart (To see all files / directory within the current folder, even HIDDEN Files)
- code . (To Launch VS Code)
Thats All Folks! Happy Coding ☮
@SelfTaught-HamzaCodes
Copy link
Author

smpt.ehlo() Everyone,

This is my very first GIST.

Please spare any in-conveniences, as I am a begginner.

Kindly let me know of any mistakes I could reivse.

PeaceOut!

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