Everything I Know So Far About Git/GitHub...for now
Published: 2023-12-19 01:15:28

This is just the very basics of Git/GitHub as I am still learning the ins and outs of this complex tool! 

**Introduction**
Git is a version control system that helps manage changes made to files and directories in a project. They allow you to keep track of what you did when, undo any changes you decided you don't want, and collaborate with others. 

GitHub is a web-based hosting service for git repositories. 

_Basically, it is like when working on a Google Docs where you have multiple people making edits to a document and you can see the edit histories and possibly revert to an old version._

**Basic Terminologies**
- Local repository(repo): a local directory containing code and files for the project. (_aka your personal computer_)
- Remote repo: an online version of the local repository hosted on services like GitHub
- Cloning: making a clone or copy of a repository in a new directory
- Commit: a snapshot of the project you can come back to
-Branch: a copy of the project used for working in an isolated environment without affecting the main project
- Git merge: the process of combining two branches

**Installation and Set Up**
I don't feel well-versed enough to explain the installation process so I've attached a link on how to install and set up: [Link](https://evanwill.github.io/get-git-b/content/2-install.html)

**Git Basic Commands** _(These are my everyday commands)_
1.) To create a local repo, clone a repo from a remote host(GitHub): 
	`git clone <the_remote_repo_url>`
_(Note: you will need to fork a repo on GitHub to get the URL. Forking is getting your own copy of the repo)_

Just click on the fork button and it will take you to another page, click create fork and then copy that url. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rv6nllyxgwbxwesmqlln.png)


2.) See the current status of your local repository:
	`git status`

3.) Create a branch: 
	`git branch <name_of_branch>` 
_(Note: 'git branch' can show you which branch you are currently on)_

4.) Switch into an existing branch named <branch>:
	`git checkout <new_branch>`

5.) Add all untracked/tracked files inside the current directory to git:
	`git add .`

6.) Saving a snapshot of the staged changes with a custom message:
	`git commit -m "Commit message"`
_(Note: be careful of what you write for the message because it will be difficult to revise the message in the future)_

7.) Saving staged/unstaged changes to stash for later use:
	`git stash`
_(Note: stash is great for when you want to save the edit but are not ready to commit the changes. You put them off to the side.)_

8.) List remote repos in details:
	`git remote -v`

9.) Push a copy of the local branch named branch to the remote repo:
	`git push <remote_repo> branch`

For example: 
```
(learn-env) julie@Julie ~ % git push origin main
```
Here, I am taking all the changes I made on my local repo (my computer) and "pushing" them onto my remote repo (in GitHub) which is called origin, and specifically onto my main branch.

10.)  Pull a copy from remote branch named branch to the local repo:
	`git pull <local_repo> branch`

For example,
```
(learn-env) julie@Julie ~ % git pull upstream main
```
So, same as the previous example. Here, we are “pulling” new updates from a remote repo (from GitHub) and syncing the changes to my local computer. Upstream is the name of the remote repo and main is the name of the branch you are taking the updates from. 

**Avoiding a merge conflict**
Luckily, I have not experienced a merge conflict (fingers crossed). The only advice I can offer right now to avoid a merge conflict is to communicate with your collaborators when you are adding/committing changes to the repo. It always comes back to communication. 

**More Resources**
This is just the tip of the iceberg with the commands.
Here's a list of some of the more commonly used commands for Git/terminal:
[More commands](https://www.atlassian.com/git/glossary#commands)

*P.S. I will be continuously expanding on this list as I learn more features of Git/GitHub! :)*