A collection of useful GitHub commands and procedures
Shell command to pull changes from the remote for all subdirectories in the current directory.
find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull origin master \;
For your convenience - since the syntax may not be easy to remember - you can put this command into a shell script and save it into your main GitHub directory to conveniently pull all changes for all your contained GitHub repositories via
sh pull_all.sh
Replace local changes with most recent contents from HEAD
.
git checkout -- <file>
Fetches the most recent files from the remote and resets the master branch to those by overwriting all local changes.
git fetch --all
git reset --hard origin/master
####Connecting to GitHub and GitLab servers via SSH
If you want to communicate to the GitHub/GitLab servers via a "more secure" connections or if your are using a terminal that doesn't support https
.
Create a new branch called "develop"
git branch develop
Switch to new branch
git checkout develop
Alternative shorthand for creating and switching:
git checkout -b develop
Delete the branch
git branch -d develop
Push branch to the remote server:
git push origin develop
Preview differences between branches
git diff <source_branch> <target_branch>
Merge changes from new branch back into the master branch
git checkout master
git merge develop
Add individual files
git add <file>
Recursively add everything in the current directory
git add .
Commit changes
git commit -m 'some commit message'
Shorthand for adding all files and committing them in 1 command
git commit -a -m 'some commit message'
Removes staged (add
ed files from the commit)
git rm --cached <file>