Important things about git that are easy to overlook for me, by me… and other observations.

Michel Milmore
4 min readJul 28, 2022
Photo by Robert Bakiev on Unsplash

After going through Git 101 Module and Git 102 Module of the Devslopes Web Academy webdev course, I came up with a few observations that I would like to share with the readers. Without futher due, here we go…

If we make changes to a branch, and then we switch branches BEFORE WE COMMIT OR STASH those changes,
those changes will be dragged over to the branch we checked into.

And what is wrong with that you asked?

If the changes you’ve made were totally disruptive to the flow of the programming and were full of bugs,
you now have those “breaking-code” instructions and bugs in the current branch (!!).
And plus, git won’t allow you to commit the current branch.
It would say something like, “we started the current branch with a difference between the local repository and the remote repository, we should have started with both beeing the equal…”

So, what to do about it?

Photo by Massimo Virgilio on Unsplash

In the branch we made changes to, we could do:
1) an add/commit of the changes;
2) a git restore to discard the changes; or,
3) a git stash.

“What is a git stash” did I hear you say?

The video didn`t get into what a git stash is, it just went ahead and used it. So I will expand the given knowledge by adding a few git stash references:

git stash temporarily shelves (or stashes) changes you’ve made to your working copy so you can work on something else (another branch), and then come back and re-apply them later on. — www.atlassian.com

Where is git stash saved?

All are stored in the folder .git/refs/stash on your local computer. git stash saves stashes indefinitely,
and all of them are listed by git stash list. — stackoverflow

How do I recover my git code after stash?

To retrieve changes out of the stash and apply them to the current branch you’re on, you have two options:
git stash apply STASH-NAME, applies the changes and leaves a copy in the stash.
git stash pop STASH-NAME, applies the changes and removes the files from the stash. — www.freecodecamp.org

Photo by Jeremy Bezanger on Unsplash

In order to delete a branch, you have to make sure that you are not currently on that branch; then do: git branch -D <name-of-the-branch>

Crytal clear (ie self-evident) :)

Comparing 2 branches:

git diff main..about-page

and the result could be something like:

— — a/index.html -> this is the first branch to compare, the main branch;
+++ b/index.html -> this is the second branch to compare, the about-page branch.

whenever git shows a line of code with a plus sign in front of it, that means that line is in the 2nd branch but not in the 1st branch

<body>
<div>
<h2>Title</h2>
+ <h4>About</h4>
<ul>…
Photo by Ian Barsby on Unsplash

gitignore

to ignore a folder and everything in it:

/folder_name

Useful git command for removing accidentally pushed or committed files, this will not delete it locally

git rm — cached name_of_the_file

to prevent it from being pushed to git again,
just add the file to your .gitignore file

git clone (your back end)

git clone <github http address> then
fix .env file then
intall npm package

you’re on branch feature-2 and you want to merge branch feature-1 to branch feature-2:

git merge feature-1

you realize that you didn’t want to do this…

git merge — abort

Photo by David Ballew on Unsplash

Pull Request : changes reviewed by a team or collaborators

Maybe (most likely) during a pull request, the remote main has been modified, so…

anytime you’re creating a new branch of the main branch, do a git pull first on the main branch to make sure that they are synced.

  • In my modest experience, some deployment sites work with github, you don’t just go on their site and put your files there (with ftp or usb key or cd (wait, what ?)),
    and it’s a good thing (done automatically (Vercel) or with a git clone command (Digital Ocean)
Photo by Tengyart on Unsplash

And lastly,

a philosophical thought or 2:

how descriptive the commit comments should be?
unfortunatly, we don’t get taught enough on pragmatism…

which leads me to:

The question: “Why should I do web dev?” is not a web dev question…

Michel Milmore

--

--