- Git Download
- Visual Studio Code - My preferred IDE for any programming language with git integrated
-
Ensure you are in a new, clean directory with a
README.md
file -
Create repo
git init
-
Set branch name to "master" or whatever branch name you want
git branch -m master
-
Set origin to GitHub repository. Where
<url>
is the URL of your git repository.git remote add origin <url>
-
Add files to commit
git add .
-
Commit the files
git commit -m "init"
-
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"
git push -u origin master
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.
- Make some changes to code/files
- Add them. You can do
git add <file>
individually instead.git add .
- Commit you changes and annotate what you changed
git commit -m "<DESCRIBE YOUR CHANGES>"
- Repeat steps 1 - 3 until you want to update remote repository
- Push commits. If you are pushing a branch that does not exist remotely, you will need to
git push -u origin <branch>
git push
git init
git clone <url>
git pull # -r
-r
rebase all local commits on top commits pulled from repo
git push
--set-upstream origin <branch>
/-u origin <branch>
Pushes branch to remote
git add <files>
-a
will stage all files
This will open a text editor to briefly describe your changes.
git commit
-m "<message>"
Passes message rather than opening a text editor--amend
Adds staged changes to the previous commit
git branch <name>
If you include a name, it will create a new branch with that name from your currently active branch.
-a
Lists all local and remote branches-d <branch>
Deletes a branch-m <branch>
Renames a branch
Should commit all changes before checking out.
git checkout <branch>
-b
Creates and switches to a new branch
git reset
HEAD~1
Undos last commit--hard
Deletes all local changes
git log
--pretty=oneline
prints everything nicely in one line
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