Skip to content

Instantly share code, notes, and snippets.

@ksferguson
Last active September 19, 2018 01:04
Show Gist options
  • Save ksferguson/09e41fe7e9a12463f2965bd2dd4b3c37 to your computer and use it in GitHub Desktop.
Save ksferguson/09e41fe7e9a12463f2965bd2dd4b3c37 to your computer and use it in GitHub Desktop.
Git(Hub) Cheats #github #cheats

GitHub Cheats

misc git commands

cd ~/github
mkdir <repo_dir>
cd <repo_dir>
git init

git clone <repo_URL>
git clone [email protected]:ksferguson/<repo>.git
(or clone from github.com web page)

git add <new_file>.txt
git add --all
git commit -m "added <new_file>.txt to the repo"

git remote add <remote_name> <remote_repo_url>
git pull <remote> <branch>
git push -u <remote_name> <local_branch_name>
  
git commit -m "added changes to fix xyz"
git push origin master

branch

#Lists all local branches in the current repository
git branch

#Creates a new branch
git branch [branch-name]

#Switches to the specified branch and updates the working directory
git checkout [branch-name]

git merge [branch]

gists

I wanted a copy of my gists in my local repo in case I'm unconnected and need one of my cheats, so I setup as follows to avoid having to copy and paste the long names for each gist.

  • clone each gist repo into ~/github/gists/ folder (grab clone link from each gist page)
  • create three shell commands to iterate over the long meaningless repo names
bash check-gists.sh
bash push-gists.sh
bash pull-gists.sh

check-gists.sh

find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && echo '{}' && git status" \;

push-gists.sh

find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && echo '{}' && git push origin master" \;

pull-gists.sh

find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "cd '{}' && echo '{}' && git pull" \;

git config/setup

git config --global user.name <yourusername>
git config --global user.email <yourgithubemail>
git config --system core.editor <editor>

git config --global alias.st status 
git config --global alias.co checkout 
git config --global alias.br branch 
git config --global alias.up rebase 
git config --global alias.ci commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment