GIT

References

http://gitref.org

Everyday Operations

Starting a development project

Getting code from an existing repository

git clone [git url]

Initiating a new repository

git init .

Starting a new development day

git checkout development
git pull origin
git checkout [working branch name]
git merge development

Pushing/Update to a repository

git push [remote] [branch name]

Checking out from a remote repository branch name to a local remote different branch name

git checkout -b [local-branch-name] [remote]/[remote-branch-name]

Pushing to a repository with a different branch name

git push [remote] [local branch name]:[remote different branch name]

Pulling from a repository

git pull [remote] [branch name]

Branch Management

List Remote Branches

git branch -a

List Local Branches

git branch

Checking outs from a specific file from a repository

git checkout [branch name] [file path]

Renaming a branch

git branch -m [old_branch] [new_branch]

Deleting a branch locally

git branch -D [branch name]

Deleting a branch remotely

git push origin :newfeature

Resetting a branch from remote

git reset --hard [remote]/[branch]

Remove local branches that no longer exist in a remote repository

git fetch --prune <remote repository>

Other alternatives for pruning local branches

git remote prune [remote]
git branch --merged [development] | grep -v "\* [development]" | xargs -n 1 git branch -d

File Management

Removing a file from git repository without removing the file locally

git rm --cached [file name]

Stashing files

This is particular useful if you want to reset a branch. I typically use this in the case when I accidentally made changes to master instead of the proper branch

Stashing the changes

git stash

Show what is in the stash

git stash show

Applying the changes from the stash

git stash apply

Keeping either files in a conflict

Reference: http://gitready.com/advanced/2009/02/25/keep-either-file-in-merge-conflicts.html

Picking the source branch file instead of the one you have in this branch

git checkout --ours filename

Picking your file in the branch instead of the one in the source branch

git checkout --ours filename

Creating a submodule

Reference: https://chrisjean.com/git-submodules-adding-using-removing-and-updating/

To link a directory to another git repository

git submodule add [git repository url] [target directory]

To clone a repository with a sub-module in it

git clone --recursive [git repository url]

 

 

Opinions about People, Process and Technology

Optimization WordPress Plugins & Solutions by W3 EDGE