Git. Git what? GitHub.

Basics for Beginners

When I started Bootcamp, I had no idea what Git or GitHub was; I just copied and pasted commands provided by instructors or project demos. I wish I would have taken the time earlier in my journey to learn and understand more about them. In hopes of preventing you from the same frustrations I faced, here are some basics.

Git

Git is version control software that is installed locally on your machine.

Version control, also known as source control, is the practice of tracking and managing changes to software code. Source

When you start a new project, from inside your project directory in your text editor, use the git init command to initialize a new repository.

A Git repository is a virtual storage of your project. It allows you to save versions of your code, which you can access when needed. Source

As you add or revise code, git tracks local changes. When you're ready to save those changes, use either git add <file_name> (for individual files) or git add . (all recently changed files) to add changes to the git staging area. The staging area is essentially a container that holds all the files you want to save to your git repository in the next commit. It allows you to add and remove files freely until you run git commit -m "commit message" which then pushes/saves all local changes to your repository. The files in your repo that were added to the staging area are now up to date with your local working directory files.

A couple of other git commands I found useful in the beginning:

git status - allows you to see files that contain changes, shows both staged and unstaged files

git diff - shows you exactly what code has changed in each file (useful if you're like me and get so caught up coding that you forget to make commits)

git - lists common git commands and what they do

GitHub

I find myself embarrassed to admit this but realize everyone starts somewhere (and I cannot be the only one, right?). Initially, I had no idea that Git and GitHub were two completely separate things.

GitHub is a Web-based Git version control repository hosting service Source

Basically, it is a place to store your projects online. As long as you know that git repositories are stored locally and GitHub repositories are remote copies, separating concerns shouldn't be too difficult.

When you are ready to create a remote repository for your project on GitHub, you will need to create a new repository in your account on GitHub. Once you've created the repo, you should see a screen similar to this:

16146326-E7B6-4FCC-8AA3-6460F75CBE6D.jpeg

If you haven't already run git init locally, follow the instructions to add a new repository from the command line (with a few changes). Here's an explanation of each command:

echo "# test" >> README.md - this will create a new file called README.md with the text '# test' in it. You really only need to do this if you don't have any files in your project yet.

git init - initializes a LOCAL git repository

git add README.md - only run this if you only have the README.md file; if you have other project files, run git add .

git commit -m "first commit" - only run this if you haven't previously made any commits

git branch -M main - names the default branch 'main'

git remote add origin git@github.com:ortufte/test.git - tells git to use your GitHub repository as your remote repository

git push -u origin main - pushes all files in the default(main) branch to the remote(origin) repo

Now, if you have already started creating files and adding code before creating a GitHub repo, you can use the second option to push an existing repo from the command line. NOTE: If you haven't made any commits yet, make sure to do that before following the steps outlined. The commands here are also used in the first option, so I won't repeat them here.

Conclusion

I hope this is enough information to give you a basic understanding of Git and GitHub and how they work together. As my knowledge of the topic increases, I will share what I learn in follow-up blog posts.

*Sources:

https://www.edureka.co/blog/git-vs-github/ https://www.atlassian.com/git/tutorials/setting-up-a-repository https://www.javatpoint.com/git-origin-master*