owned this note
owned this note
Published
Linked with GitHub
# Git and GitHub

---

---

---
### What is git?
- Version Control System (VCS)
- helps you document and store changes you made to your file throughout time
- Every time you change something in your file and save it, you can commit that change.
- Gives you the ability to add comments to your changes
---

---

---
### Why do we need it?
- You can see changes to the document throughout time
- You can go back to any point! ( As long as you "commited ")
- It helps keep track of changes done to specific file over time by specific users
---

---
### Cloning
The most common way of accessing a remote repo is by cloning it. For that, you can use the well-known git-clone command.
`git clone https://github.com/vuejs/vue.git`
Such command automatically creates all remote branches and checkouts the main branch (most often named "master").
---
### Branches
The problem with multiple people working on the same project comes in the form of managing changes that overlap, while not disrupting one another. Git has a solution to that too - it's called branches!
Branches, thinking of Git as a tree, help people have their separate version to work on. Branches can be based on one another, with the main one called "master", created after your first "branch-less" commit.
`git branch -b my-branch`
---
### Checkouts
After creating a new branch, you'll have to "move" to given branch, to be able to apply all the operations you commit from now to it. To change your current branch, to another, you'll need to use the git checkout command.
`git checkout my-branch`
---
### git add
Let's say that you've already had or just created a new file with some content that you'd like to commit to your Git repository. Here's how you can do this:
`git add .`
With above command we add all our files (you can specify them with whole directories or file by file) to somewhat container, i.e. we stage our changes, to make Git notice that they've been changed - created, updated or removed.
---
### git commit
`git commit -m "Commit message"`
The git commit command doesn't need to take any files or directories as an argument, as they're already known because of previous add command. Instead, here we can pass some additional information about our current commit itself.
---
### Merge
Finally, changes done by multiple people need to be somewhat merged together. To do this, Git provides an intuitively-called command - git merge. With a simple call, you can merge provided branch with the current one. To make the process easier, Git will ask you every time a collision happens between file changes or proceed automatically if it's not needed.
`git merge my-branch`
---
### Push
Accessing remote origins would be pointless if you wouldn't be able to apply changes to them. To push your changes from the current branch to remote one, you can use git push command.
`git push origin my-branch`
git push takes two arguments - first points at the remote origin by its name and the second selects the branch from remote origin to push changes too. Pretty straight-forward, huh?
---
### Git is not GitHub !
- Git is a revision control system, a tool to manage your source code history.
- GitHub is a hosting service for Git repositories.
- So they are not the same thing: Git is the tool, GitHub is the service for projects that use Git.
---
## References
- [FAC Workshop](https://github.com/foundersandcoders/git-workflow-workshop-for-two)
- [Red Badger's beginner's guide to Git](https://blog.red-badger.com/2016/11/29/gitgithub-in-plain-english)