Git Workflow & Common Pitfalls/Mistakes
git workflow
(first time setup) clone the repository
git clone https://github.com/dryu99/infinite-animal-crossing-lofi.git
- what does cloning the repository mean?
- you're "grabbing" the latest version of the code from GitHub
- you only need to do this once at the beginning
- this is what it could look like
- what does cloning the repository mean?
check out a new branch
git checkout -b NAME-OF-BRANCH
- it should look like this:
- the name of the default branch in my example is called
CREDITSS
(shown in a blue colour)- the default branch is called
master
by default, although it varies by repository
- the default branch is called
- we checked out to a new branch called EXAMPLE
- the name of the default branch in my example is called
- checking out a new branch means that you're working on a different version
- like a paper - this means you're working on a draft involving one idea for the final paper
- you don't want to work on the idea directly on the final paper but rather on a draft
- if you don't use the "draft" having branches makes it easier to not include it
- if you do use the "draft" you can easily put it in the final paper - master
- it should look like this:
- make your changes, go wild!
- you can add something to the README or do some code!
- tell git to track your changes by doing
git add .
- try to do this in the beginning before you start making any changes
git add .
will add ALL changes; you can add only some changes by specifying a file instead of.
- save your changes and give it a meaningful name by doing
git commit -m "describe your changes here"
- double check to see what git is keeping track of by doing
git status
- push those changes up to github
git push origin NAME-OF-BRANCH
- go to github and make a pull request!
- merge it into master branch
Common Pitfalls/Mistakes
common pitfalls
- help! what do i do if my git says "failed to push some refs to origin"
- you wanna pull your changes and do
git pull origin master
- you wanna pull your changes and do
- help! i wanna revert to an earlier version!
- find the last time you saved your work by doing
git log
and keep track of the hash - then
git reset --hard <hash>
- find the last time you saved your work by doing
- how do i update my local version to be up to date with github?
git pull origin NAME-OF-BRANCH
will update the a specific branch
- how do i switch branches?
git checkout NAME-OF-BRANCH
common mistakes
- not including spaces between your commands
gitcommit
vsgit commit
- not pushing or pulling your repository
- not pulling -this means that you aren't working on the latest version of the project
- not pushing - that means you haven't uploaded the latest version of the project
- working on the wrong branch
- you meant to do it in branch A but you did it in branch B
- check which branch you're on in git
- working on the master directly (if there are multiple people working or different versions)
- similarly to a paper, it would be as if you're working on the final paper rather than a draft