DEV Community

Louie Aroy
Louie Aroy

Posted on • Edited on

Git cheatsheet

Add all files to be saved

git add .
Enter fullscreen mode Exit fullscreen mode

Save changes offline

git commit -m "Changed something comment"
Enter fullscreen mode Exit fullscreen mode

Push changes to online server

git push
Enter fullscreen mode Exit fullscreen mode

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

git stash

# delete stash
git stash drop
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

Remove remote origin to reupload files to source control provider

git remote remove origin
Enter fullscreen mode Exit fullscreen mode

Upload repo to source control provider

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

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"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Use git to maintain website in server
http://toroid.org/git-website-howto

Top comments (0)