Alltop
The most commonly used git commands are: add Add file contents to the index bisect Find by binary search the change that introduced a bug branch List, create, or delete branches checkout Checkout a branch or paths to the working tree clone Clone a repository into a new directory commit Record changes to the repository diff Show changes between commits, commit and working tree, etc fetch Download objects and refs from another repository grep Print lines matching a pattern init Create an empty git repository or reinitialize an existing one log Show commit logs merge Join two or more development histories together mv Move or rename a file, a directory, or a symlink pull Fetch from and merge with another repository or a local branch push Update remote refs along with associated objects rebase Forward-port local commits to the updated upstream head reset Reset current HEAD to the specified state rm Remove files from the working tree and from the index show Show various types of objects status Show the working tree status tag Create, list, delete or verify a tag object signed with GPG
branchestop
List Branches ----------------- git branch git branch -r Create New Branch and check it out ----------------------------------- git checkout -b new_branch_name Merge Branch into master ----------------------------- 1. git checkout master 2. git merge new_branch_name Git push amster or branch to remote ----------------------------------- git push (for master) git push origin branch_name (for branch) Delete branch from local and remote ----------------------------------- # update local first git fetch -p origin git branch -d new_branch_name (from local) git push origin :plugin_branch (from remote) git pull master and remote branches ------------------------------------ git pull (master) git pull origin remote_branch (remote branch) Forked branch pull from origin/master ------------------------------- git fetch upstream git merge upstream/master Push branch to remote ------------------------ git push -u origin plugin_branch ---------------------------------- This tells git to push changes from your plugin branch to the plugin branch on the origin repository. If origin does not have a plugin branch, it is created on the fly. The -u tells git that you want to be able to easily push and pull changes to that branch in the future. Updates another repository ---------------------------- git fetch origin git checkout --track origin/plugin_branch The first command updates another repository with the changes from the remote repository. The second command creates a local branch named plugin_branch that matches the origin/plugin_branch and tells git that this repo now wants to be able to easily push and pull from the branch on GitHub. Bob can now play with the code, commit his own changes and git push them back up to the GitHub repository.
change a remote repository URItop
git remote set-url origin git://new.url.here
git remote set-url origin ssh://[email protected]/home/user/new.url.here
clonetop
cd to dir where you want actual project files to live in
git clone [email protected]:user/project_name.git .
delete filetop
# remove file from file system and repo git rm somefile.txt git commit -m "removed somefile.txt" # remove file from repo only git rm --cached somefile.txt # remove whole directory git rm -r dir
delete filetop
# Remove from file system and repo git rm file1.txt git commit -m "remove file1.txt" # Remove from repo only git rm --cached file1.txt
delete repotop
rm -rf .git
difftop
**Check diff between remote and local** Add files to a 'cache' of remote files then check. So, suppose you've got a remote called origin that refers to your GitHub repository, you would do: git fetch origin ... and then do: git diff master origin/master **Check diff between remote and local (commits only)** Add files to a 'cache' of remote files then check. git fetch origin git cherry master origin/master *** check diff between branches dig diff branch1...branch2
fetch / prunetop
#Fetch all of the branches from the repository. git fetch <remote> # Same as the above command, but only fetch the specified branch. git fetch <remote> <branch> #fetches all registered remotes and their branches git fetch --all #perform a demo run of the command. git fetch --dry-run # To update the local list of remote branches: git remote update origin --prune
ignoretop
.gitignore file per project .git/info/exclude per repo http://gitready.com/beginner/2009/01/19/ignoring-files.html ignore specific file that "is" tracked I define the following aliases in my .gitconfig file: [alias] ignore = update-index --assume-unchanged unignore = update-index --no-assume-unchanged That should do exactly what you want: running git ignore some-file will treat the file as unchanged no matter what you do to it, until you run git unignore some-file. http://stackoverflow.com/questions/5011390/git-ignoring-a-file-which-is-version-controlled How to view untracked files and clean them out git clean -ndX Explanation: git help clean git-clean - Remove untracked files from the working tree -n, --dry-run - Don't actually remove anything, just show what would be done. -d - Remove untracked directories in addition to untracked files. -X - Remove only files ignored by git. Note: This solution will not show ignored files that have already been "cleaned."
initalize repotop
cd Dir git init
mergetop
Merge Brand into master 1. git checkout master 2. git merge new_branch_name If conflicts and you want to go back to previous state git merge --abort Check for conflicts first git checkout -b mycrazybranch [change some stuff...] git add . git commit -m "changed some stuff" git format-patch master --stdout > crazy.patch git checkout master git apply crazy.patch --check [all good! cleanup...] rm crazy.patch
Quickstart githubtop
Create a new repository on the command line touch README.md git init git add README.md git commit -m "first commit" git remote add origin [email protected]:user/project.git git push -u origin master Push an existing repository from the command line git remote add origin [email protected]:user/project.git git push -u origin master # Add existing code to new Repo on github https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
removetop
Remove file from Repo (no more commits) git rm --cached myfile.php
rmtop
# Remove file from repo and filesystem git rm filename
stashtop
git stash (this will save changes in correct branch without committing) git stash pop (this will bring back your changes in correct branch)
undo git pulltop
# If you pull into the wrong branch git reset --hard ORIG_HEAD
Undo last mergetop
git reset --hard HEAD~1 # Be aware that any modified and uncommitted/unstashed files will be reset to their unmodified state.