Skip to content

Git and Github

BK Jackson edited this page Nov 25, 2024 · 107 revisions

gitdataflow

Git Subpages

Git Workflow Cheatsheet

https://github.com/hackalog/bus_number/wiki/Github-Workflow-Cheat-Sheet

Starting the day. Where was I? What was I doing?

git branch         # What branch am I currently on? e.g. {my_branch}
git status         # anything I forgot to commit? If so...
git commit ...     # Commit work in progress

Didn't I do some work at home last night?

git checkout master       # leave whatever branch I was on
git fetch origin --prune  # Check for something new
git merge origin/master   # If updates available, update!

Anything fun happening upstream?

git checkout master
git fetch upstream --prune  # grab latest changes from upstream repo
git merge upstream/master   # merge them into local copy of my form
git push origin master      # push latest upstream changes to my forked repo
git branch --merged master # check for any merged branches that can be safely deleted
git branch -d {name_of_merged_branch} # delete any fully merged branches

Now that master is up to date, you should merge whatever happened in master into your development branch:

git checkout {my_branch}
git merge master               # merges master->{my_branch}
git push origin {my_branch}    # Let Github know about the merge  

Dealing with proxies

Configure Git to use a proxy
For error unable to access '...' Couldn't resolve host '...'

git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port  

Git logs

Formatting Git logs with simple output:

git log --pretty=format:"%h - %an, %ar : %s"

Find version ID with git log and checkout old version:

git log index.html  
git checkout <version ID> index.html  

Set up git in a new project directory

git init
git add .
git commit -m "initial git setup in <my-project>"   

Cloning

Clone an existing git repository:

git clone <url>  

Clone a single branch from a remote git repository:

git clone -b <my-branch> --single-branch git@<remote-repo>    

Fetch any new work that has been pushed to the server since you last cloned or fetched

git fetch origin  

Branching - A branch is a label for the 'current' commit in a sequence of ongoing commits

A simple way to clean up your git project branches

Create new branch on local machine and switch to this branch

git checkout -b [name_of_new_branch]

Reverting uncommitted changes to a file (before git add)

git checkout -- <filename>  

Rename your local branch (More steps)

git branch -m new-name   

Push NEW local branch to remote

git push -u origin [name_of_new_branch]  

Changing a remote's URL

git remote set-url origin git@github.com:USERNAME/REPOSITORY.git  # SSH  

git remote set-url origin https://github.com/USERNAME/REPOSITORY.git  # HTTPS   

Create local branch that tracks remote branch

git checkout --track origin/development    

See which branches are tracking which remote branches

git branch -vv   

Take new commits from group development branch and add them to personal development_joe branch

git checkout development
git pull  
git checkout development_joe  
git merge development  

Cancel a git merge

git merge --abort  

Take only select files from one branch to master

git checkout master  
git checkout development README.md  
git commit -m 'Merging updated README.md file'  

See last N commits and dates they were committed

git log -5 --pretty=format:"%h - %an, %ad : %s" --date=local  

Pull Requests from the command line with request-pull

git request-pull [-p] <start> <url> [<end>]  
  • -p —  Running request-pull without that option will output a summary of changed files. -p is more verbose and will output all changes that have been made from the split commit to the end one.
  • <start> —  Is the starting point you want to merge to. Most of the time we will give it the master branch and git will calculate the start commit on its own. The start commit is the common ancestor from which the feature branch split.
  • <url> —  Is the repository to compare to. It can be a local repository and it can be a remote one.
  • <end> —  The end point we want to stop comparing to. Usually we won’t state the end commit because we would like to merge all recent changes.

Steps:

git checkout -b <feature_branch>  
git request-pull master ./

# Run a comparison from feature branch to master.  

Push local branch to remote repository

git push origin development_joe  

Delete a local branch

git branch -d the_local_branch  

Git Config

Configure Git Settings on your computer:

git config --global user.name "Your UserName"  
git config --global user.email "yourname@email.com"  

Check config settings on your machine:

git config user.name  
git config user.email  

View remote repositories:

git remote -v  

Tell Git to use osxkeychain helper using the global credential.helper config:

git config --global credential.helper osxkeychain  

Git add - places modified versions to staging

# Add a single file  
git add my_notebook.ipynb  

# Add all changed files, reviewing changed files first  
git status     
git add .  

Find out who last changed a file

git blame <filename>  

Change a filename tracked by git

git mv file1.txt file-newname.txt  

Create a .gitignore file

touch .gitignore  
    # Add rock as a submmodule of slingshot  
    git submodule add https://github.com/<user>/rock rock  

    # Download contents of the submodule rock  
    git submodule update --init --recursive  

Managing Line Endings in Git Across Windows and Linux/Unix/MacOSX

Mind the end of your line

Git on Azure

Git Credential Manager for Mac and Linux on Azure

Git Hooks

What are Git hooks?
Git hooks are scripts that Git executes before or after events such as: commit, push, and receive. Git hooks are a built-in feature - no need to download anything. Git hooks are run locally.
githooks.com - the missing manual
Autohook - Autohook is a very, very small Git hook manager with focus on automation.

Git Tips

A collection of useful .gitignore templates
10 Git Commands You Should Know - Jeff Hale, Feb. 28, 2019
Git tip: How to "merge" specific files from another branch
GitHub Forking Workflow

Git Docs & Guides

Git Official Docs
Understanding the GitHub Workflow
Git quick reference
Official gittutorial Manual Page
Gitref.org - Git reference site & tutorial
How to undo almost anything with Git
Git Immersion Guided Tour
Git for Designers - My [Notes] (https://github.com/BKJackson/BKJackson_Wiki/wiki/Version-Control-for-Designers-%7C-Notes)
Git for Computer Scientists
Git Ready: Learn git one commit at a time
Git-SCM Useful links
A List Apart - Getting Started with Git: See notes for this article here.
Atlassian Git Tutorials

GitHub Docs & Guides

Understanding the GitHub Flow 5 minute read.
Github Help
Github - Bootcamp
Learn GitHub.com

Tutorials & Courses

Introduction to Git and GitHub for Python Developers
MIT Git Intro Dhruv Jain
Version Control with Git From Software Carpentry (~3 hour lesson plan)
A git Primer Daniel Miessler
Updating Git on Mac OS X
git-it A workshop for learning Git and GitHub. Based on this guide Git-it.
Version Control Best Practices
Get the Most Out of Git: 7 Best Practices for Budding Developers
Software Carpentry: Version Control with Git

Books

Pro Git, by Scott Chacon

Cheat Sheets

Err the Blog - Git Cheat Sheet
Everyday GIT with ~20 Commands Manual Page

Videos

Pro Git Videos
Hitler is Informed That He Uses Git

GitHub Pages

GitHub Pages Home - Includes instructions for getting set up.
Using Jekyll as a static site generator with GitHub Pages - For customizing GitHub pages.
Jekyll templates
Creating a GitHub Pages site with the Jekyll Theme Chooser
Creating and Hosting a Personal Site on GitHub - Step-by-step beginner's guide.
Cayman Jekyll Theme

Github / Safari issue

Flush DNS cache when Github freezes Safari windows:
http://osxdaily.com/2015/11/16/howto-flush-dns-cache-os-x-elcap/ Reference: OSX 10.10.1 Safari freezing when browsing Github.com (And some other cases)
https://discussions.apple.com/thread/6687771?start=0&tstart=0

Other (old) Git Notes Pages

Getting Started with Git | Notes Old notes.

Clone this wiki locally