KingOfDetroit
Helpful Git Commands
- Check which branch you're on with
git branch
- Create a new branch with
git switch -c branch_name
- or simply switch to an existing branch with
git switch branch_name
- To add and commit your code:
git add .
adds all your changesgit commit -m "add message here"
commits your changes to the current branchgit push -u origin branch_name
pushes your code to the desired branch
- Once your branch has been merged into main, you can then switch to main, pull those changes, and delete the working branch!
git switch master
git pull origin master
git branch -d branch_name
Resolving Merge Conflicts
A pain in the you-know-what. A few options that have worked for me:
- Option 1:
- Run
git stash
will stash all the changes you have made - Run
git pull origin master
- Run
git stash pop
to bring your changes back up. Go into the files and clean up all the conflicts.
- Run
- Option 2:
- In your branch run
git merge branch_name
to merge changes INTO your branch - This will likely cause merge conflicts that you'll need to go in and fix
- In your branch run
- Option 3:
- Push your code to your own branch so it's saved
- Copy and paste the code you're trying to bring in
- ... then just add in your changes to that