If you’re just getting into Git, it can be confusing. This is a step-by-step checklist that can be used by a new person to know exactly what commands they need to type to use Git during a normal coding session. Follow this from when you sit down to code and just want to start on some new work, using your team mates most recent code as your starting point. This assumes you are using a branching model where every person works only on their own branches (i.e. 2 people never edit the same branch), and then merge their changes into a single central branch via pull requests.
Triangular Workflow Note: If you are using a triangular workflow (you pull from one Github repository to get the latest changes, but you push to a different copy i.e. your fork) note the slightly different command in the step for getting the latest changes.
Central Branch Note: This workflow assumes ‘dev’ is the main branch to work off of. If your team uses a different central branch (e.g. master) substitute that branch name.
C:\Users\Documents\MyCoolRepo>) –> go to 2. b. No (e.g.
C:\Users\Documents>) –> use
cd my\pathuntil your command line shows you are in the main project folder.
git fetch --all
Make sure you’re starting from a clean slate on your local repository:
Do you have any modified files?
git add -Ato stage all your files
git committo make a new commit on your current branch
git branch useful-branch-name
git checkout useful-branch-name
git add -Ato stage files
git committo make a commit on your new branch.
git checkout dev
git reset --hardWarning this deletes the changes you’ve made to the current files. Only do it if you actually want to throw away your changes (i.e. if you broke something). Everything that’s been committed is still accessible.
git cleanWarning This one deletes any new files that have been created. Reset only deals with files that were edited/removed, clean only deals with files that were added.
dev) –> all good!
git checkout dev
git statusshould return the result “On branch dev”, and “nothing to commit, working tree clean”. If not, try above steps again.
Add the latest changes from the remote repository (i.e. Github) into the copy of the
dev branch on your computer.
a. Triangular workflow:
git pull nameoftheremote dev
b. Single-repo workflow:
git pull origin dev
git branch my-branch-name
git checkout my-branch-name
git statusshould reveal “On branch my-branch-name” and “nothing to commit, working tree clean”. You’re ready to start working!
git statusshould reveal “On branch my-branch-name” and a list of all the files you’ve edited.
git add -A
git commit -m "very descriptive text that tells what changes I made to the code"(if you forget the commit message and get stuck in the weird VIM editor a) here’s how to get out and better yet b) configure your git to use a better text editor.
git push -u origin my-branch-name(read about -u)
dev), you can make a new pull request to do so.