DEV Community

Discussion on: Beginner Git/GitHub Workflow Tutorial: Start Using Git TODAY with these Basic Commands

Collapse
 
waylonwalker profile image
Waylon Walker

Great tips Anna! I really like that you include branching in your guide. So many guides just start committing right into main. In my experience, the minute that I get main broken with a crazy change, someone asks for a simple fix and I need to get my work off of main and into its own branch.

If you forget to branch

I do this often

get everything committed (you can always stash, but I like this way).

note reset --hard will lose work if you do not have it saved to another branch.

$ git status

On branch main
Your branch is ahead of 'origin/main' by 1 commit.

$ git branch long-term-feature # save your work to a branch
$ git reset origin/main --hard   # line up your main and remote main
$ git status

On branch main
Your branch is up to date with 'origin/main'.

 # now checkout a new branch starting from where main is to start the quick fix
$ git checkout -b quick-fix     
Collapse
 
annajmcdougall profile image
Anna J McDougall

Great addition, thanks Waylon! Yes it's tough sometimes to decide what should go into a beginner tutorial because on the one hand, you don't want to overload with too much information. On the other hand, you want to build good habits early. I'm glad you agree with the call I made on that one :)