Skip to content

Instantly share code, notes, and snippets.

@wiccy46
Last active September 24, 2020 19:10
Show Gist options
  • Save wiccy46/776a33d7e3d7c65b541c732fc377af3c to your computer and use it in GitHub Desktop.
Save wiccy46/776a33d7e3d7c65b541c732fc377af3c to your computer and use it in GitHub Desktop.
[GITCheat]Git Cheat Sheet #git

Add an existing project

  1. Create a new repository on GitHub. You can also add a gitignore file, a readme and a licence if you want
  2. git init
  3. git add .
  4. git commit -m "initial commit"
  5. git remote add origin remote_repository_URL
  6. git remote -v
  7. git push -f origin master

Delete Branch

Local:

git branch -d the_local_branch (or use -D to force it)

Remove:

git push origin --delete the_remote_branch

Rename directory

git mv <old name> <new name>

Casesensitive rename: using tmp as a buffer

Delete all commit history of master but keep the current one.

  • Checkout git checkout --orphan latest_branch

  • Add all the files git add -A

  • Commit the changes git commit -am "commit message"

  • Delete the branch git branch -D master

  • Rename the current branch to master git branch -m master

  • Finally, force update your repository git push -f origin master

Print upstream URL

git config --get remote.origin.url

Rmove directory from git and local

git rm -r one-of-the-directories // This deletes from filesystem git commit . -m "Remove duplicated directory" git push origin <your-git-branch> (typically 'master', but not always)

Squash commit

git pull
git checkout <your_branch>
git rebase -i master
git push -f origin <your_branch]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment