Using Git

Reference: Version Control with Git (2nd Edition covers Github), John Loeliger & Matthew McCullough, O'Reilly

Configuration files


(In decreasing priority!)
.git/config: repository specific config
~/.gitconfig: user specific config
/etc/gitconfig: system config

Configuring github user

Fernandos-MBP-2:~ fbarreir$ git config --global user.name "XXXX"
Fernandos-MBP-2:~ fbarreir$ git config --global user.email "YYYY"
Fernandos-MBP-2:~ fbarreir$ git credential-osxkeychain
usage: git credential-osxkeychain <get|store|erase>   #MEANS ITS INSTALLED!
Fernandos-MBP-2:~ fbarreir$ git config --global credential.helper osxkeychain
Fernandos-MBP-2:~ fbarreir$ git config -l
user.name=XXXX
user.email=YYYY
core.editor=emacs
credential.helper=osxkeychain
The next time you clone an HTTPS URL that requires a password, you'll be prompted for your username and password, and to grant access to the OSX keychain. After you've done this, the username and password are stored in your keychain and you won't be required to type them in to Git again.

Setting up aliases

git config --global alias.show-graph \
'log --graph --abbrev-commit --pretty=oneline'

Query the state of an index

git status
git ls-files
git ls-files --stage

#Diff between your local repository and some branch
git diff --stat --cached origin/master

File statuses


Tracked
Untracked
Ignored: Specified in .gitignore

Inspecting the history of commits

gitk
git bisect
git blame -L 35, init/version.c

Branches


Create branches
git branch prs/pr-1138 #Create branch from HEAD
git branch prs/pr-1138 rel-2.3 #Create branch from tag rel-2.3
git branch prs/pr-1138 db7de5feebef8bcd18c5356cb47c337236b50c13 #Create branch from commit

Inspect branches

git branch
git show-branch
git show-branch bug/pr-1 bug/pr-2

Change your working directory to a branch

git checkout bug/pr-1
git checkout -b bug/pr-3 #Create a new branch and switch to it

Get remote branch to track locally

git pull
git checkout --track origin/retrial

Merges

The git merge operation is context sensitive. Your current branch is always the target branch, and the other branch or branches are merged into the current branch.

git merge alternate
git log --graph --pretty=oneline --abbrev-commit

Syncing a fork

https://help.github.com/articles/syncing-a-fork/
git remote -v #List the current configured remote repository for your fork
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
git remote -v #A new remote repository named upstream should have shown up
git fetch upstream #Get all the updates from the original repository
git checkout master #Go to the branch you want to update
git merge upstream/master #Merge the changes from upstream master to your local master branch

Working with remote repositories

git fetch: Retrieves objects and their related metadata from a remote repository.
git pull: Like git fetch, but also merges changes into a corresponding local branch.
git push: Transfers objects and their related metadata to a remote repository.
git ls-remote: Shows a list of references held by a given remote (on an upstream server). This command indirectly answers the question Is an update available?
Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r4 - 2015-10-02 - FernandoHaraldBarreiroMegino
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback