Skip to content

Instantly share code, notes, and snippets.

@AlexMercedCoder
Last active August 9, 2023 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexMercedCoder/20044b84d8f100148d9d5edd2d15386c to your computer and use it in GitHub Desktop.
Save AlexMercedCoder/20044b84d8f100148d9d5edd2d15386c to your computer and use it in GitHub Desktop.
Git Cheatsheet

Basics

Creating a new repository in the current working directory

git init

see what files are and arent in staging

git status

Adding Files to staging

git add filename.ext #Add a single file
git add -A #add all unstaged files throughout repo
git add . #add all files in current directory and sub directories

to commit

git commit ## will open an editor to write a commit message
git commit -m "commit message"

git remotes

git remote add <name> <URL> ## add a remote
git remote rm <name> ## remove a remote
git remote -v ## list all the current remotes

push and pull

git push <remote_name> <branch_name> ## Sending the remote commits
git pull <remote_name> <branch_name> ## receiving commits from the remote

git clone

git clone <URL_OF_REPO>

git branch

git branch ## see list of branches
git branch <name_of_new_branch> ## create a new branch

git checkout

git checkout <branch_name> ## switch to a branch
git checkout <commit_hash> ## switch to a particular commit
git checkout <tag_name> ## switch a particular tag (named commit)
git checkout -b <branch_name> ## creates a new branch and switches to it

git merge

git merge <target_branch_name> ## merges the target branches commits into the commits of the current branch your on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment