$ git log --oneline
A branch is essentially another copy of your repo that will allow you to isolate changes and leave the original copy untouched.
You can later choose to combine these changes in whole or part with the another branch or the mainline of development, or not.
This is the shared branch that you will deploy to production. Feature branches are merged in when your team agrees.
This is where you will do your development work. Open a pull request to master when you're ready to merge.
$ git checkout -b user-authentication
Create a new feature branch from the master branch like this:
branch name: MASTER
Since you are deploying, it makes sense to have a branch that you all agree will be deployable at all times. Merge the dev branch here when it's ready to deploy.
Don't introduce broken code to the production branch!
This is where you will do your development work. Push this up and open a pull request to the shared dev branch.
branch name: DEVELOPMENT
This is where you will merge separate feature branches. Code might be broken here. It gives you a place to push changes and share work.
* This is basically the GitHub Flow.
On local FEATURE branch:
Make your commit(s).
On local MASTER branch:
$ git pull origin master
Make sure local master is up to date with remote master.
$ git merge master
Keep this branch up to date with master.
If there are merge conflicts, resolve them here on the feature branch.
You can create a pull request on GitHub whenever you want, using their big green button
👆This command merges your local master into the feature branch.
$ git push origin feature-branch
PULL OFTEN so you will have your colleagues' work.
PUSH OFTEN to keep your remote branch up to date.
COMMIT OFTEN to collaborate effectively.
PULL REQUEST so team members can review your work.
MERGE feature branches to master on GitHub.
It's your job to keep your feature branch up to date with master.
Tell your team when you are pushing up changes or have opened a pull request that requires their review.
Say why a change is needed or what it does.
Make sure your local and remote branches are in sync.
Merging brings two lines of development (branches) together, still preserving the history of each commit
$ git checkout master $ git pull origin master
$ git checkout featurebranch $ git merge master
👉 OPEN A PULL REQUEST* ON GITHUB & MERGE THERE
When new code has been merged to remote master
When you have just pulled changes down from remote master
When you are ready to incorporate your feature into the main line
Create a pull request when you want a collaborator to look at and approve changes on your branch.
GitHub: How to create a pull request
Conflicts occur when changes occurred in each branch to the same line or group of lines, and git doesn't know which to choose.
Here are lines that are either unchanged from the common ancestor,
or cleanly resolved because only one side changed.
<<<<<<< HEAD
Your changes are reflected here in this section.
=======
Their changes are here in this section, in conflict with yours.
>>>>>>> other-branch
And here is another line that is cleanly resolved or unmodified.
The area where a pair of conflicting changes happened is marked with markers <<<<<<<, =======, and >>>>>>>.
The part before the ======= shows your changes,
and the part afterwards shows their changes.
All you need to do is edit the file that the conflict is in so that it is the way you want.
Delete everything, including the stuff git put in that file, that should not be there.
...and the file has gone back to its state at the previous commit 🎉
If you haven't added (staged) files or committed yet.
$ git checkout app/views/layouts/application.html.erb
👉🏾 Your changes are gone from the working tree (and your editor)
(replace this path with the path to the file you want to get rid of changes in)
The file is removed from staging, but your working copy will be unchanged.
$ git reset app/views/layouts/application.html.erb
When you want to keep the changes in your working tree
$ git checkout app/controllers/main_controller.rb
Your changes are gone from the working tree.
Reset the working tree to its state at the last commit
You can reset a file first and then unstage it:
$ git checkout app/controllers/main_controller.rb
$ git reset app/controllers/main_controller.rb
Or, if you want to discard everything, use the --hard option:
$ git reset --hard
Rewind, but learn to live with your regrets.
$ git revert 53d23c4
👆🏽Notice that the original bad commit is still there, but now you also have another commit that undoes the changes introduced by the original one.
$ git log --oneline
👆🏽Your default text editor will open; you can just save it as is.
$ git log --oneline