Skip to content

Latest commit

 

History

History
76 lines (40 loc) · 2.27 KB

README.md

File metadata and controls

76 lines (40 loc) · 2.27 KB

GitPractice

example workflow

  1. Fork this repository on github.

  2. Clone your fork. In a terminal in some folder to store repositories:

git clone https://github.com/*your_username*/GitPractice.git

  1. Enter the repo directory:

cd GitPractice

  1. Add this "master" repository as a remote:

git remote add upstream https://github.com/tlacasse/GitPractice.git

  1. Check the results, see your remote (fork) is named "origin" and the master one is named "upstream":

git remote -v

  1. Switch to master branch (which you are already on, but practice):

git checkout master

  1. Get all changes from the remotes:

git fetch --all

  1. Get current "master" code (be careful with any git reset --hard, but should be safe here):

git reset upstream/master --hard

  1. Create a new feature development branch:

git checkout -b branch

  1. Make sure you have the lastest changes before each session of development, (see rebase -i explained later):

git fetch --all

git rebase upstream/master -i

  1. Make a change to the file testfile.txt, where it says <make change here>.

  2. Stage your changes, I recommend using some other software for this, to better specify which files to stage and even which individual lines. Else research git add.

  3. Commit the staged changes:

git commit -m "message"

  1. Push to your fork:

git push origin branch

  1. To practice merge commits, at the previous point there was git rebase upstream/master -i, but for practice we will do:

git rebase upstream/otherwork -i

  1. Here in the interactive rebase you can make changes to commit history, for now just exit the editor.

  2. You should get a merge conflict, because two people worked on the same bit of code. In an file editor, you can choose to keep their changes or your changes. Choose what is appropriate, but here just pick one, and recommit the commit.

  3. Continue on:

git rebase --continue

  1. This is where you continue development, but any time history is rewritten, you must force push to your remote branch to overwrite it:

git push origin branch --force

  1. And you should be done. That is the general development process.

  2. Finally you will want to create a pull request from your fork to the original repository (done on github). Never push directly to master.