- Create a new repository on github
- with a README.md + LICENCE + .gitigore
clone
the repository to your computer- usually somewhere in
~/git
- usually somewhere in
- In the
README.md
file definegit clone
andgit init
git add
andgit commit
your changesgit push
your changes back up to your github repository
git clone <URL>
: "downloads" the repository to the current directorygit init
: initializes the current directory as a git repo
git branch <NAME>
: creates a branch where HEAD isgit branch -a
: lists all the branchesgit switch <NAME>
: moves HEAD / switches your branch togit checkout <NAME>
older way to switch branches
- create a branch
branch_defs
- edit README
git log --oneline --graph --all
git push
- pull request
- add/commit changes
- push branch
- create the PR
- merge the PR
- sync our local
main
withorign/main
fetch --prune
- delete local branch
git log --oneline --graph --all
: show you a decorated historygit push <REMOTE> <BRANCH>
: push a branch to the remote, pay attention to what branch you're working on
-
git fetch
: updates the git log / historygit fetch --prune
: deletes any remote branches that were deleted
-
git branch -d <NAME>
: delete branch on your local machine -
pull requests will auto update when you push the branch again
git fetch --prune
git switch main
git pull origin main
git switch <BRANCH>
git rebase main
: command to incorporate main into current branch
Code to simulate conflicts:
git checkout -b conflict_branch_1
echo "Changes to b1 commit 1" >> README.md
git status
git add README.md
git commit -m "b1 c1"
echo "Changes to b1 commit 2" >> README.md
git add README.md
git commit -m "b1 c2"
git checkout main
git checkout -b conflict_branch_2
echo "Changes to b2 commit 1" >> README.md
git add README.md
git commit -m "b2 c1"
echo "Changes to b2 commit 2" >> README.md
git add README.md
git commit -m "b2 c2"
git push origin conflict_branch_2
git push origin conflict_branch_1
-
branch protection rules: need PR + do not allow bypass + do not need review
A convention people use for branches to separate "main"/"production" for "development" code
- Probelm: I just want to be at another place (in git)
git reset --hard <HASH>
- you get the
<HASH>
fromgit log --oneline