https://github.com/bluefrog130/git
https://github.com/bluefrog130/git
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bluefrog130/git
- Owner: BlueFrog130
- Created: 2021-01-26T14:08:45.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-01-26T16:43:21.000Z (over 5 years ago)
- Last Synced: 2025-06-26T22:05:48.549Z (12 months ago)
- Size: 70.3 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Git Tutorial
- [Git Download](https://git-scm.com/downloads)
- [Visual Studio Code](https://code.visualstudio.com/) - My preferred IDE for any programming language with git integrated
## Getting Started
0. Ensure you are in a new, clean directory with a `README.md` file
1. Create repo
```bash
git init
```
2. Set branch name to "master" or whatever branch name you want
```bash
git branch -m master
```
3. Set origin to GitHub repository. Where `` is the URL of your git repository.
```bash
git remote add origin
```
4. Add files to commit
```bash
git add .
```
5. Commit the files
```bash
git commit -m "init"
```
6. Intial push. Ensure you are pushing to the name you gave to remote and the branch name you set. In this example the remote name is "origin" and the branch name is "master"
```bash
git push -u origin master
```
## Workflow
The philosiphy of git is to seperate your code changes into small, readable commits. You may stack up as many commits locally as you like, and push them when you are ready.
### Typical Workflow
1. Make some changes to code/files
2. Add them. You can do `git add ` individually instead.
```bash
git add .
```
3. Commit you changes and annotate what you changed
```bash
git commit -m ""
```
4. Repeat steps 1 - 3 until you want to update remote repository
5. Push commits. If you are pushing a branch that does not exist remotely, you will need to `git push -u origin `
```bash
git push
```
## Common Git commands
### Initializes repository
```bash
git init
```
### Clones repository into a folder
```bash
git clone
```
### Pull latest commits from repository
```bash
git pull # -r
```
#### Most Used Options
- `-r` rebase all local commits on top commits pulled from repo
### Push all local commits to the remote repository
```bash
git push
```
#### Most Used Options
- `--set-upstream origin `/`-u origin ` Pushes branch to remote
### Stage changes to be committed
```bash
git add
```
#### Most Used Options
- `-a` will stage all files
### Commit all staged changes
This will open a text editor to briefly describe your changes.
```bash
git commit
```
#### Most Used Options
- `-m ""` Passes message rather than opening a text editor
- `--amend` Adds staged changes to the previous commit
### List all branches
```bash
git branch
```
If you include a name, it will create a new branch with that name from your currently active branch.
#### Most Used Options
- `-a` Lists all local and remote branches
- `-d ` Deletes a branch
- `-m ` Renames a branch
### Switch to a branch
Should commit all changes before checking out.
```bash
git checkout
```
#### Most Used Options
- `-b` Creates and switches to a new branch
### Resets all commit to HEAD
```bash
git reset
```
#### Most Used Options
- `HEAD~1` Undos last commit
- `--hard` Deletes all local changes
### Log commits
```bash
git log
```
#### Most Used Options
- `--pretty=oneline` prints everything nicely in one line
---
## Useful Aliases
Aliases are essentially custom git commands that are defined in `C:\Users\%USER%\.gitconfig`
```
[alias]
co = checkout
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
undo = reset HEAD~1 --mixed
amend = commit -a --amend
```