DEV Community

Cover image for GitBash breakdown for beginners! Use git the way you would need to in a company position!
Danny Thompson
Danny Thompson

Posted on

GitBash breakdown for beginners! Use git the way you would need to in a company position!

If you like this article, chances are you'd like what I tweet as well. If you are curious, have a look at my Twitter profile. Or check out my podcast! "Commit Your Code!" Where we interview and talk to some phenomenal developers and motivate you to stay on the coding journey!

The last thread was about uploading a project to github using a simple method. But in any company you work you are going to need to use git or terminal.
Have git bash installed then follow.

First go to github & press New.
Now we need a repository name. A repository is the space we are saving our code in. You can add a description to explain what is in this space, so if you come back after a few months you can remember what is in there.

Now lets go ahead and create the repository!

repository menu

Copy the URL in the box. And now go to the folder you have your project in.

Copy the URL

Navigate to the folder you have the project in. I lead a group called GDG Memphis, so that is what I named this folder.

Right click and you will see the option Git Bash here. Press it. If you do not see that, go to git bash and navigate to your folder. I will show you how.

Folder

You can type cd which stands for change directory and this will allow you to go into another folder. You can go 1 at a time or a way to do it faster would be

cd coding/GDGMemphis/gdgmemphis

This will give the same result as what you see below. Either way will work.

Git bash cd

So we need to initialize the folder. We will do that by using

git init

This is making a .git folder and will be necessary so we can push the contents of this folder. After the init I used git status to see what the status is of the files in this folder.

git init

Here i added our files. Notice the red file names are now green? This shows the files that we have added so that we can commit them.

to add files just do
git add
OR!
git add .

The period means add everything in this folder.

git add

Now we need to COMMIT the files. Committing means we want these files to be sent to our github repository! To commit we'll use

git commit -m "our message"

ALWAYS write a good commit message. this text will be displayed next to the file name. Professional developers PRAISE detailed messages! Definitely do them.

commit

Now here is where we add the URL of where we will send our COMMIT or our Files!
so we will use

git remote add origin https://github.com//

Remember that URL we copied above from the Third image? Time to use that bad boy and paste it in!

remote

You can't use ctrl + v to paste. you have to right click and paste or use CTRL + Shift + insert! Now you know why we have an insert key on our keyboard! lol After that type

git push -u master origin

The master branch is the main branch.

push

When you work in a company, you will be expected to work on your OWN branch. after the code is reviewed and tested, then you will MERGE that branch to the master! So how can we do that? Super easy!

branch
Notice the green text on the right? Shows which branch we are on!

A working branch is great and will prevent you from destroying the original code by accident! GET USED TO THIS! Vital in any business setting!

git branch creates the branch
git checkout switches you to that new branch!

You have made it the whole way! This was a lot! I WISH I spent more time learning git before getting hired and not knowing how to navigate branches!

You made it the whole way and you are incredible!

Proud of you

Follow me on Twitter!

Top comments (2)

Collapse
 
xanderyzwich profile image
Corey McCarty

good writeup!

Collapse
 
dthompsondev profile image
Danny Thompson

Thank you!🙏🏽❤️