engineering:computer_science:git:resources:git_cheatsheet

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
engineering:computer_science:git:resources:git_cheatsheet [2024/08/16 13:56] – removed - external edit (Unknown date) 127.0.0.1engineering:computer_science:git:resources:git_cheatsheet [2024/08/16 13:56] (current) – ↷ Page moved from refractor_computer_science:git:resources:git_cheatsheet to engineering:computer_science:git:resources:git_cheatsheet carlossousa
Line 1: Line 1:
 +======  ======
 +
 +====== Git Cheatsheet ======
 +
 +===== Initialize & Add Remote Git =====
 +
 +<code bash>
 +git init
 +git remote add origin <url>
 +git fetch
 +git branch --set-upstream-to=origin/<branch> master
 +git pull
 +
 +
 +</code>
 +
 +===== Push Changes to Remote Git =====
 +
 +<code bash>
 +# Add all changes to the commit
 +git add .
 +# Commit with Comment
 +git commit -m "<comment>"
 +git push
 +
 +
 +</code>
 +
 +===== Delete All Commit History =====
 +
 +<code bash>
 +# 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
 +
 +
 +</code>
 +
 +===== Pushing new branch requires username / password =====
 +
 +<code bash>
 +# Fix with
 +git remote set-url origin git@github.com:<username>/<rep>.git
 +
 +# Push the branch
 +git push origin <branch-name>
 +
 +</code>
 +