git it got it good - ipatch/dotfiles GitHub Wiki
to turn any directory into a git repo run the following command within the directory
git init
to remove git from a directory / project, just delete the .git
directory in the root of the project.
to add a remote repo for a git project
git remote add origin <URL>
to display the remote URL’s of a git project
git remote -v
to copy a remote git repo to a local box run the below command
git clone <URL>
to stage all the changes displayed from git status
run the below command
git add .
or
git add -A
to commit all the changes for a push to the remote repo run the below command
git commit -m “Commit local changes”
to push all the committed changes to a remote repo run the below commandto push all the committed changes to a remote repo run the below command
git push
git pull
is a shortcut of two other git commands
git fetch
git merge
git fetch; git merge
to create a new branch that isolates a feature / fix run the below command
git branch new-feature
to display all the branches of a git repo run the below command
git branch
to switch to the new-feature
branch run the below command
git checkout new-feature
to create a new branch and switch to it run the below command
git checkout -b new-feature2
to switch to the last checked out branch run the below command
git checkout -
will switch back to the master
branch
to combine the new-feature
branch with master
run the below commands
git checkout master
git merge new-feature
to delete a branch after everything is complete with it, run the below command
git branch -d new-feature
A merge conflict arises when the local and remote code both change, and it can’t be resolved with a standard
git pull
orgit push
There are three possible scenarios to resolve a merge conflict usegit status
to see the file in question that is causing the merge conflict
git stash
allows you to save your local changes after staging them
git add .
git stash
git log
will show a history of all the commits to a remote repo
git log
can take arguments like the below command
git log {arguments}
some sample git log
arguments are listed below
git log --oneline
git log --decorate
git log --graph
git log -p
git log --stat
a useful example of combining arguments is listed below
git log --oneline --graph
to see the three most recent commits run the below command
git log -3
below are various git log
commands with arguments
git log --after=”yesterday”
git log --author=”ipatch”
git log --no-merges
Compare file changes with git diff
git diff --stat
git diff --cached
to see who modified a file last run the below command
git blame someFile.rb
to see a list of tags in a repo run the below command
git tag
to create a tag for a repo, run the given example below
git tag v1.0.0
to push the local tags to a remote repo, run the following
git push --tags
to grab the latest version of the remote code, use following
git fetch
to rebase a branch interactively run the below command
git rebase -i origin/master
git bisect
allows you to track down a problem in code on a commit to commit basis.
to start a bisecting state run the below command
git bisect start
to label a commit good / bad run the following command
git bisect bad
git bisect good
a test suite such as Rspec can run all its test before a git commit
is made
Example - create the following file in .git/hooks/pre-commit
the below command will write to the global .gitconfig
in the user’s home dir
git config --global
to set the editor for git run the below command
git config --global core.editor vim
aliases can be created using something similar to the below command
git config --global alias.graph ‘log --graph --oneline’
Remove unnecessary tracking git tracking with .gitignore files to remove a tracked file from a git repo
git rm --cached
to remove ALL .DS_Store
files from a git repo add the below line to .gitignore
**/.DS_Store
These notes wouldn't be possible if the below course wasn't created.
git for everyday professional use
...and @kyleknoche I hope you find these notes useful.
cheers 🍻
Chris