GIT Cheat Sheet
This will show you files that need to be staged for a commit.
On branch masterYour branch is ahead of 'origin/master' by 1 commit.(use "git push" to publish your local commits)Changes not staged for commit:(use "git add/rm <file>..." to update what will be committed)(use "git restore <file>..." to discard changes in working directory)deleted: public/old.cssUntracked files:(use "git add <file>..." to include in what will be committed)public/new.css
This will take a directory that is not managed by git and tell git to start tracking files.
This command tells git to add all the files in the directory to a commit. NOTE,
you will have to do a
git commit later to actually make the commit
git add .
Alternatively you can add specific files
git add public/new.css
This command will allow you to save changes you aren't ready to commit so that you can do other work in the repository such as switching branches or working on other code.
The command alone won't stash untracked (new) files, to stash those at the same
git stash --include-untracked
Shows you the list of stashes you've stored
git stash list
Brings back code from a specific stash
git stash apply "Name of stash"
git stash pop
git commit -m "Your descriptive commit message"
As long as the commit has not been
git push yet you may change the message
(and the contents)
git commit -amend -m "Your corrected descriptive commit message"
This will push to whatever the
origin is, in most case this is github.
This will pull down new code from whatever the
origin is, in most case this is
Pull from original repo to update local (you can also use
upstream master if
you have multiple branches)
git pull origin master
Clone an existing repository from a URL to a local directory. This will make a copy of the code from the URL and put it in a directory based on the last part of the URL
git clone <url to repository>
If you get conflicts when merging code you can undo the merge and revert to the code before the merge started.
git merge --abort
git checkout branchName
git checkout master
This will checkout the previously active branch
git checkout -
This creates a new branch using the current branch/commit as the starting point
git checkout -b newBranchName
Takes your branch back one commit, but your changes are still in the working tree
git reset HEAD~1
Takes you back to that specific commit, losing all the commits since then. You
HEAD~1 to mean "Back one commit from the current commit"
git reset --hard specificCommitName
This will let you merge changes from
git checkout branchNamegit merge --no-ff otherBranchgit push origin branchName
If you want to hack on open source projects (including this handbook) you will the following steps:
- Click Fork in upper right of repo on Github
- Clone your fork onto your computer (see above)
- Checkout a branch to contain your changes
git checkout -b <branch-name>
git fetch upstreamgit checkout mastergit merge upstream/master
Creating a PR via your Fork
If this repository is a fork, the message from github may include a link to create a pull request.
- Open your forked repo on github
- Create PR from your forked repo on github