Git Cheat Sheet
This Git Cheat Sheet is a work in progress. If you'd like to suggest an addition then please comment below.
Passwords
Update your password when it changes .. an easy way which prompts for your new password
git pull
Ignoring files and directories
Place a .gitignore file in your top level directory with one entry per row
e.g.
test_output
Whenever a directory called "test_output" is found, git will not consider it for changes.
Branches
Passwords
Update your password when it changes .. an easy way which prompts for your new password
git pull
Ignoring files and directories
Place a .gitignore file in your top level directory with one entry per row
e.g.
test_output
Whenever a directory called "test_output" is found, git will not consider it for changes.
Branches
View all the local branches
git branch
View all the remote branches
git branch -r
View all the remote AND local branches
git branch -a
Switch to the branch <branch-name>
git checkout <branch-name>
Find out branch you are on
git branch (* row in results denotes the current branch)
Find out branch you are on
git branch (* row in results denotes the current branch)
Stashing
View all the stashes
git stash list
Stash changes
git stash / git stash save
Restore a stash that was not the last one stashed (need to manually remove from the list)
git stash apply stash@{1}
Remove a stash from the list
git stash drop stash@{1}
Restore a stash and remove it from the list
git stash pop
a particular stash ...
git stash pop stash@{1}
View the contents of a particular stash
Feature Branch Workflow
git checkout -b <feature-name> <branch-feature-diverts-from>
git add <some-file>
git commit
// for remote backup or incorporation into code base
git push -u origin <feature-name>
// rebase feature
// to merge the feature
git checkout <branch-feature-diverts-from> // switch
git pull // get up to date
git pull origin <feature-name> // merge
git push // update repository
View all the stashes
git stash list
Stash changes
git stash / git stash save
Restore a stash that was not the last one stashed (need to manually remove from the list)
git stash apply stash@{1}
Remove a stash from the list
git stash drop stash@{1}
Restore a stash and remove it from the list
git stash pop
a particular stash ...
git stash pop stash@{1}
View the contents of a particular stash
git stash show -p
Feature Branch Workflow
git checkout -b <feature-name> <branch-feature-diverts-from>
git add <some-file>
git commit
// for remote backup or incorporation into code base
// rebase feature
git checkout <branch-feature-diverts-from>
git pull
git checkout <feature-name>
git rebase <branch-feature-diverts-from>
then follow the instructions from git
use 'git status' if you get lost
OR!!!
git merge <branch-feature-diverts-from>
This is easier if a lot of changes have happened in the feature branch as rebasing
replays ever add and the next rebase you do you have to replay every add all over again
// to merge the feature
git checkout <branch-feature-diverts-from> // switch
git pull // get up to date
git pull origin <feature-name> // merge
git push // update repository
Comments
Post a Comment