10 pretty useful git commands

Add existing local git to Github

git remote add origin   # Sets the new remote git remote
git remote –v # Verifies the new remove URL
git push origin master # Pushes the changes from your local repo to github

(from https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ )

Remove a file from the watchful eyes of git

Add the file to the .gitignore file

Git rm –cached

Deleting branches local and remotely

git branch –d <branch-name>  # deletes local branch
git push origin :<branch-name>  # deletes the remote branch

from (http://stackoverflow.com/questions/2003505/how-to-delete-a-git-branch-both-locally-and-remotely )

Create branch and push to remote (i.e. Github)

git checkout –b  #First, create the branch locally
git push   # To push it to the server

(from http://stackoverflow.com/questions/1519006/how-do-you-create-a-remote-git-branch )

List all the files for a commit

git show –pretty=”format” –name-only

Squashing git commits with rebase

(useful prior to merging in a feature branch back into a main branch and you reduce the number of commits in that history)

git rebase -i HEAD~4 # allows you to wrap the last four commits into one commit

(from http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html )

Diff local and remote branches

git diff <origin/branch>   #e.g. git diff origin/develop develop or if you just want to list out the files that are different
git diff –stat origin/develop develop

Quickly view conflicted files in GIT

git diff –name-only –diff-filter=U

Removing multiple deleted  files in Git

git rm $(git ls-files –deleted)

or

git diff –diff-filter=D –name-only -z | xargs -0 git rm

Duplicating a git repository

git clone –bare https://github.com/exampleuser/old-repository.git # Make a bare clone of the repository cd old-repository.git
git push –mirror https://github.com/exampleuser/new-repository.git # Mirror-push to the new repository
cd .. rm -rf old-repository.git # Remove our temporary local repository (from https://help.github.com/articles/duplicating-a-repository)
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s