DEV Community 👩‍💻👨‍💻

Louie Aroy
Louie Aroy

Posted on • Updated on

Git cheatsheet

Add all files to be saved

git add .

Save changes offline

git commit -m "Changed something comment"

Push changes to online server

git push

Undo local changes and save them if you want to revert again

git stash

# delete stash
git stash drop

Apply new gitignore

# "cache/" is the file or folder you want to remove tracking
git rm -r --cached cache/
git add .
git commit -m ".gitignore is now working"

Remove remote origin to reupload files to source control provider

git remote remove origin

Upload repo to source control provider

git remote add origin https://username@your.bitbucket.domain:7999/yourproject/repo.git 
git push -u origin master

Merge branches

# list local branches
git branch

# create a new branch
git checkout -b new_branch

# switch to a branch
git checkout branch_name

# merge the new branch to master branch
git checkout master
git merge --squash new_branch
git commit -m "new_branch and master branch merged"

Delete a branch

# delete a local branch
git branch -d branch_name

# force delete a local branch
git branch -D branch_name

# delete a branch on github/bitbucket
git push remote_name --delete branch_name

Use git to maintain website in server

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.