doubularity.dev

Git Guide for Goobers

🥋

Originally written for Cal-Poly-RAMP/carp-core.

By the end of this guide,

disclaimer: if you have any git wizardry, corrections/opinions, or want to submit other git resources feel free to contribute. if you are looking for more, start with man git (optional subcommand) and get greppin’

round 1 (ง’̀-‘́)ง

git init

initializes a new repository - by default this will also create:

[I] ~[1]►git init slop       21:15

git status

[I] ~/slop►git status                                           (master) 21:15
On branch master

No commits yet

git add (files)

[I] ~/slop►touch good_code.c                                 (master) 21:22
[I] ~/slop►git add .                                       (master|?) 21:22
[I] ~/slop►git status                                      (master|●) 21:23
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
	new file:   good_code.c

git commit -m “your description”

🗿 it’s a good idea to run add & commit early and often

especially if you know the changes you made so far are currently working - it’s easier to jump through commits than sort through a commit with 100 new lines and refactored code

[I] ~/slop►git commit -m "implemented matrix mul"          (master|●) 21:24
[master (root-commit) e2e6fca] implemented matrix mul
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 good_code.c

git push

round 2 (ง’̀-‘́)ง

git branch 🌿


[I] ~/slop►git branch                                        (master) 21:30
* master

git switch 𓀓𓀝

[I] ~/slop►git switch -c adding_new_function                 (master) 21:31
Switched to a new branch 'adding_new_function'
[I] ~/slop►git branch                           (adding_new_function) 21:31
* adding_new_function
  master
[I] ~/slop►                                     (adding_new_function) 21:31

WARNING: beware 👹 git checkout

just don’t use git checkout - it’s an old command they keep around for back-compat. If you see git checkout (something), there’s a very good chance it can be done instead with:

  • git switch
  • or git restore

git log 🪵

[I] ~/slop►git log                                     (adding_new_function) 21:38
commit ff2453df2d14aef8b68fe5c0b11fcbd1e56ec101 (HEAD -> adding_new_function)
Author: d <[email protected]>
Date:   Sun Nov 16 21:37:38 2025 -0800

    implemented some other func

commit e2e6fca7a4d87781994946e8b4a77a3288f6b937 (master)
Author: d <[email protected]>
Date:   Sun Nov 16 21:24:56 2025 -0800

    implemented matrix mul

git restore

[I] ~/slop►rm function_code.c                          (adding_new_function) 21:44
[I] ~/slop►rm good_code.c                           (adding_new_function|💩) 21:44
[I] ~/slop►git status                               (adding_new_function|💩) 21:44
On branch adding_new_function
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	deleted:    function_code.c
	deleted:    good_code.c

no changes added to commit (use "git add" and/or "git commit -a")
[I] ~/slop►git restore function_code.c              (adding_new_function|💩) 21:45
[I] ~/slop►git status                               (adding_new_function|💩) 21:45
On branch adding_new_function
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	deleted:    good_code.c

no changes added to commit (use "git add" and/or "git commit -a")

git diff

[I] ~/slop►git diff                                 (adding_new_function|💩) 21:51
diff --git a/function_code.c b/function_code.c
index 82a5457..0b84d41 100644
--- a/function_code.c
+++ b/function_code.c
@@ -1 +1 @@
-void old_function() {}
+int new_function(int a) { return a + 1; }

round 3 - going back to main branch

♫ who says you can’t go home? ♫

git merge (best for simple changes that do not conflict)

im running out of breath explaining in exhaustive detail, and you’re going to have to do your own research anyway. so heres an example. you’ll figure it out, i believe in you!

the master has become the student 🏅

git switch main
git merge my_cool_feature_branch 

three things could now happen:

alternatives to git merge:

github pull requests (my preferred method):

Bonus Round:

git stash / git stash pop

terms

License

This project is licensed under the GNU General Public License v3.0 (GPLv3).

You may copy, distribute, and modify this software as long as you track changes/dates in source files and license your derivatives under the GPLv3.
All derivative work must also be open-sourced under GPLv3.

See the full license text in the LICENSE file or online at:
https://www.gnu.org/licenses/gpl-3.0.en.html

-Dylan Joaquin Sandall