Skip to content

mxmoss/testGit

Repository files navigation

testGit

This is a small repo of small files to try out the more unusual scenarios with git / github

How can I commit to a dev branch, and once that passes testing then commit to master?

(Rather than committing all changes to the master branch) There are two simple ways to merge the dev branch into the master.

  1. 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]

  1. 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

How does this work with other people in my team?

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

What's the easiest way to create a new repo based on existing code on my system?

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

How can I show a web page from within my repo?

TBD

Comparison

Add /compare to the repo's URL, and then provide a basis for comparison

How To Temporarily Switch to a Previous Commit?

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

How can I compare two separate revisions?

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

How can I create a milepost or a release version?

TBD

How can I view multiple revisions of one file?

I'd like to see all history for one specific file.

git log -p <filename>

How can I get a subset of a repo? (ie: only the subdirectory of the main repo)?

TBD

How can I roll back a set of changes?

TBD

How can I review the 3 most recent revisions in a repo?

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 

How do I get the files from repository?

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

I want to make some changes to the local file

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

I want to see the difference between my local files and the repo

This command shows which files are different from the GitHub repo

git status

I want to commit my changes to the local file

This step commits the change and adds a message explaining the change

git commit -a -m "this is my commit message"

I want to sync the remote GitHub repo with my local files

This command pushes the local changes to GitHub

git push origin master
(it will prompt you for username & password)

I can't sync with the remote repo

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)

I have a release branch. I want to include one change from Develop in the release

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.

I want to temporarily save my current changes and work on something else

This is called Stashing. Stash current changes so you can work on something else example:

git stash 

See here for more discussion.

I messed up somewhere and just want to reset evertying

Reset current working state to the last commit or last known good commit example:

git reset useful_func.clj

See here

I committed some changes, but forgot a few

Use "amend" to add changes or comments to a commit example:

git commit --amend --no-edit 

See here

Can I use git to track down when and where bugs were added to the code?

Use bisect to track down bugs

git bisect start 
git bisect bad 

See here

Using Git on Open Source Projects

The basics

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

See here

Workflows

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

Finding Projects

About

Learning more about git

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages