This is a small repo of small files to try out the more unusual scenarios with git / github
(Rather than committing all changes to the master branch) There are two simple ways to merge the dev branch into the master.
- Through GitHub
View the branch on Github
https://github.com/mxmoss/testGit/tree/Dev
Click [New pull Request]
(Essentially https://github.com/mxmoss/testGit/pull/new/Dev )
This initiates a pull request. The pull request checks to see whether the two branches are able to merge. Write an reason for the pull request.
You will see something like this:
"mxmoss wants to merge 1 commit into master from Dev"
Click 'Merge Pull request'
Click [Confirm merge]
- Merging via command line.
You can perform a manual merge on the command line. https://github.com/mxmoss/testGit.git
git fetch origin
git checkout -b Dev origin/Dev
git merge master
Step 2: Merge the changes and update on GitHub.
git checkout master
git merge --no-ff Dev
git push origin master
When working in Github on the same file:
- Working from an existing Master
- create a Branch off Master.
- Use a name like "yourname-featname"
- eg: moss-smallfeat
- Make & test changes
- When the changes are done, create a pull request
- The person in charge of code review will review the changes
- The code reveiewer accepts the pull request
- The changes from the branch will be merged into the Master
- After that, the branch can be deleted
I use GitHub desktop. With GitHub desktop, simply drag the directory with your code onto the GitHub client. It will ask you where you want to create the repo. Accept all defaults. Bam! Repo created.
What about creating a repo from the command line?
Nope: Outside of the API, there's no way to create a repo on GitHub via the command line.
Instead: create a new repository on GitHub, then
Change the current working directory to your local project.
and push to an existing repository (eg: WeirdOrConfusing) from the command line
git remote add origin https://github.com/mxmoss/WeirdOrConfusing.git
git push -u origin master
TBD
Add /compare to the repo's URL, and then provide a basis for comparison
git checkout
This will detach your HEAD, that is, leave you with no branch checked out. The help says "You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout." Example: git checkout 0d1d7fc32
To get back to the most current commit, run checkout again with the branch name: git checkout master
a) If one of them is the most recent, and the other is a 2 weeks ago?
Comparisons can be created for arbitrary time periods, like one month or two weeks. To define a time period, type the branch name, followed by a @, and then the date wrapped between a { } notation. For example, typing master@{2weeks} into the base dropdown menu compares the current master branch against the master branch as it was two weeks prior.
Here's an example of a comparison between two time periods.
https://github.com/mxmoss/testGit/compare/master@{2weeks}...master
b) Between two specific dates?
You can also specify a specific date to compare against. Date formatting must follow the ISO8601 standard, which is YYYY-MM-DD.
Here's an example comparing a branch from 07/04/2016 against that same branch a month later.
https://github.com/mxmoss/testGit/compare/master@{2016-07-04}...master@{2016-08-04}
c) If one of them is the most recent, and the other is 2 revisions ago?
As a shortcut, Git uses the ^ notation to mean "one commit prior."
You can use this notation to compare a single commit or branch against its immediate predecessors.
For example, 96d29b7^^^^^ indicates five commits prior to 96d29b7, because there are five ^ marks.
Typing 96d29b7^^^^^ in the base branch and 96d29b7 in the compare branch compares the five commits made before 96d29b7 with the 96d29b7 commit.
This url shows a comparison between the current revision and three commits ago
https://github.com/mxmoss/testGit/compare/master^^^...master
For more information, click this link
TBD
I'd like to see all history for one specific file.
git log -p <filename>
TBD
TBD
Just as git log will show you revisions for a file, it can also list commits. Change to the directory and issue this command:
git log -3
Let's say you want to work on a repo locally on your Windows computer. These steps will make a directory:
Start | Run |Cmd
mkdir \temp
cd \temp
This command retrieves the repo "testGit" from my github account (mxmoss)
git clone https://github.com/mxmoss/testGit
These steps edit a file in the repo (assuming you've done part 1)
cd testGit
notepad TestText.txt
Type in some info. For example: "this is a change by my. My name is..."
Ctrl-S
Alt-File-eXit
This command shows which files are different from the GitHub repo
git status
This step commits the change and adds a message explaining the change
git commit -a -m "this is my commit message"
This command pushes the local changes to GitHub
git push origin master
(it will prompt you for username & password)
I get an error message: "You might need to open a shell and debug the state of this repo." Here's what to do:
- Open a git shell (in Github desktop choose Repository | Open in Command Prompt)
- run
git status
See what the suggestions are. In this case for me it said:
Your branch is based on 'origin/manas-wizard' but the upstream is gone.
(use "git branch --unset-upstream" to fixup)
This is called Cherry-picking commits into a branch. This doesn't work very well for binaries, but works great for code changes.
Let's say you have a late commit in the "Develop" branch.
- Change order of menu items Made changes in menus (commit: ab0f745) — joe.smith / githubweb
You want to merge this into the Release branch (called Prod-5.4 for this example) Here's what to do:
git checkout <dest branch>
git cherry-pick <commit (don't need to specify branch)>
example:
git checkout Prod-5.4
git cherry-pick ab0f745
The end result is that the cherry-picked change from the "develop" branch Is merged into the release branch.
This is called Stashing. Stash current changes so you can work on something else example:
git stash
See here for more discussion.
Reset current working state to the last commit or last known good commit example:
git reset useful_func.clj
Use "amend" to add changes or comments to a commit example:
git commit --amend --no-edit
Use bisect to track down bugs
git bisect start
git bisect bad
The basic step when committing to open source projects is to fork the project. Then you create your branch and you make a pull request. However, from time to time, you need to adjust your branch based on the latest changes. This is how you sync your fork to the original one.
git fetch upstream
git checkout master
git merge upstream/master
Summary:
- work off [develop]
- branch for a [feature] and merge to [develop] when complete
- branch for a [release] and merge to [develop] when tested
- merge [develop] to [master] when release is done
Summary:
- actual workflow used at GitHub
- [master] is always deployable
- branch off [master] for a [named-feature]
- open pull request to merge [named-feature] to [master] when complete & tested
- someone else reviews the changes and then merge into master
- deploy immediately
- Master only workflow
- Skullcandy workflow
- Backcountry workflow
###Links
- Good description of GitHub flow
- Understanding the GitHub flow
- Complete git reference manual
- using Markdown to format the readme.md
- Command line reference / cheatsheet
- Git FAQ Scenarios
- Git Tips and Tricks
- how to git
- Git clients for Windows and other OS
- Explore GitHub projects
- Top 25 trending GitHub repositories
- Beginner-friendly list of open-source projects
- The Most Forked projects on GitHub
- The Most Starred projects on GitHub
- The Awesome List- a comprehensive list of topics re: software development
- Highlist of the "most interesting" repositories