loading...

Git for Amateurs

highcenburg profile image Vicente G. Reyes ・1 min read

Originally posted on https://highcenburg.herokuapp.com

Make it a habit to run git status before doing anything on a repository. I just learned this today and wanted to write it down to make it stick on my mind - or get familiar with it.

1.) To create a new branch : git branch <name_of_branch>. A good practice is to name the branch with the focus of your edit.

Ex:

git branch markdown

2.) Next, run git checkout <name_of_branch> to work on your branch. Make it a habit to do small changes so it's easy to go back if you mess up.

Once done with your changes, you want to add all changes, commit to your changes and push it to your dev repository.

1.) Now you run git status to see the changes on your repository.

2.) Then run git add <filename> or you can do git add -A to add all the changes instead.

3.) Next, commit your changes by running git commit -m "Your message"

4.) Finally, you push your commit by running git push. Git will compain because GitHub doesn't know about your new branch. So run git push --set-upstream origin <branch_name>

If you want to delete a branch. We would go to the main branch then delete our branch from there.

1.) To go to the main branch, run git checkout <main_branch>

2.) Once in the main branch, run git branch -d <name_of_branch>

This is what I learned in an hour, with an example of the main repository from a mentor.

Posted on by:

highcenburg profile

Vicente G. Reyes

@highcenburg

A Self-Directed Learner, a Shopify Partner, Webflow Designer, Django Developer, a Volunteer Developer at Project Website, Community Moderator & a Podcast host.

Discussion

pic
Editor guide
 

Um okay, obviously you're learning this stuff at the moment. Here's another advice then, you can actually perform branch creation during checkout, that way you save about 0.00001 seconds and we all love to save time:

git checkout -b your-new-branch

You can also combine adding all files and commit message:

git commit -am "i'm adding it all"

And finally, instead of typing endless --set-upstream just pass -u:

git push -u origin your-new-branch

Looks like after doing all this we already saved about 0.00004 seconds.

Hello from Cebu!

 

Aha! So that's what git commit -am does. I've used that on heroku(i think) but never really understood what it did.

прия́тно познако́миться, bai! Hi from Manila!