ong-z
3/17/2016 - 5:51 AM

Git Notes

Git Notes

# Creates a local copy of a remote - remote_location tells Git where to go to find the remote (could be a web address, or a filepath).
git clone remote_location clone_name

# --branch <name> / -b <name>
# Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository’s HEAD, point to <name> branch instead. In a non-bare repository, this is the branch that will be checked out. --branch can also take tags and detaches the HEAD at that commit in the resulting repository.
# --[no-]single-branch
# Clone only the history leading to the tip of a single branch, either specified by the --branch option or the primary branch remote’s HEAD points at. Further fetches into the resulting repository will only update the remote-tracking branch for the branch this option was used for the initial cloning. If the HEAD at the remote did not point at any branch when --single-branch clone was made, no remote-tracking branch is created.
git clone -b winter --single-branch git@genie.solstice.sg:zhenming/django-fiit.git winter

# list Git project's remotes
git remote -v

# show more info of remote/branch tracking
git remote show origin
# sample output
* remote origin
  Fetch URL: git@genie.solstice.sg:zhenming/django-fiit.git
  Push  URL: git@genie.solstice.sg:zhenming/django-fiit.git
  HEAD branch: master
  Remote branches:
    master  tracked
    pillars tracked
    spring  tracked
    winter  tracked
  Local branches configured for 'git pull':
    master  merges with remote master
    pillars merges with remote pillars
    spring  merges with remote spring
  Local refs configured for 'git push':
    master  pushes to master  (up to date)
    pillars pushes to pillars (up to date)
    spring  pushes to spring  (up to date)
    winter  pushes to winter  (up to date)

# Fetches work from the remote into the local copy. Command will not merge changes from the remote into your local repository. It brings those changes onto what's called a remote branch. 
git fetch

# Integrate remote origin/master into your local master branch
git merge origin/master

# Push branch to remote origin
git push origin your_branch_name

# Git Workflow
1. Fetch and merge changes from the remote
2. Create a branch to work on a new project feature
3. Develop the feature on your branch and commit your work
4. Fetch and merge from the remote again (in case new commits were made while you were working)
5. Push your branch up to the remote for review