artimys
9/18/2017 - 2:24 AM

Git Workflows

Push a new branch to origin (Github)

https://git-scm.com/book/id/v2/Git-Branching-Remote-Branches

  1. Checkout to your local branch or create/checkout a new branch

    # example: create/checkout a new branch called 'map'
    git checkout -b map
    
  2. Push local new-branch to origin(Github) as a remote branch.

    '-u' option sets up the upstream tracking.

    # git push -u <remote-server> <new-branch>
    git push -u origin map
    

Delete remote branch from origin (Github)

https://git-scm.com/book/id/v2/Git-Branching-Remote-Branches

# git push <remote-server> --delete <branch-name>
git push origin --delete map

# or

# git push <remote-server> :<branch-name>
git push origin :map

Checkout a remote-branch from origin (Github) aka review a pull request

https://git-scm.com/book/id/v2/Git-Branching-Remote-Branches

  1. Download all branches

    git checkout master
    git fetch
    
  2. View all branches

    git branch -a
    
  3. Checkout local copy of remote branch

    git checkout <branch-name>
    

    OR if there are other remotes (instead of just 'origin')

    # git checkout-b <new-branch-name> <remote/branch-name>
    git checkout -b map origin/map  # Branch 'map' set up to track remote branch 'map' from origin.
                                    # switched to a new branch 'serverfix'
    

Rebase on local branch

  1. Be sure local master branch has the latest commits (git pull)

    # from your master branch
    git checkout master
    git pull
    
  2. checkout to local feature branch (example: map)

    git checkout map
    
  3. bring over missing master commits into the 'map' branch

    git rebase master
    

    Extra: from here we can merge feature branch to local master branch

    # switch back to master branch
    git checkout master
    
    # merge feature branch to master
    git merge map
    

Rebase origin/master to local master branch

  1. Checkout to master branch

    git checkout master
    
  2. Fetch commits and then rebase

    git fetch
    git rebase
    

Rebase remote feature branch to local feature branch (same branch)

  1. Checkout to feature branch

    git checkout assemblies
    
  2. Fetch commits and then rebase

    git fetch
    git rebase
    
    or 
    
    git pull --rebase
    

Syncing a forked repo

https://help.github.com/articles/syncing-a-fork/

# First add the upstream repo (the original repo) 
git remote add upstream <git-repo>


# Get all the latest commits from upstream to local
git fetch upstream

# After fetching, merge master tracking-branch with local master branch
git checkout master
git merge upstream/master

# Push to YOUR forked repo location

Untrack files that are already committed to history

# Removes ALL cached files
$ git rm -r --cached .

$ git add .
$ git commit -m "Clean up ignored files"