Skip to content

Instantly share code, notes, and snippets.

@keeperofthenecklace
Last active October 26, 2022 20:52
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save keeperofthenecklace/3394158 to your computer and use it in GitHub Desktop.
Save keeperofthenecklace/3394158 to your computer and use it in GitHub Desktop.
Github Cheat Sheet
Step B.) Creating a branch (and switching to the new branch in one line (Step 2)
**********
a.) git checkout -b [name of new branch]
eg. git checkout -b 2012Tryme
git fetch origin [remote-branch]:[new-local-branch] (Pulling a new branch from a remote repository)
b.) follow step 1
c.) git push origin 2012Tryme
** will add new branch to the repository on git hub
**********************
Step A.) Scheduling the addition of all files to the next commit (Step 1)
git add . OR git add -p (for prompt to accept changes)
git commit -a
git commit -am "First import"
git push origin
**********
Updating your remote repository.
***********************************************
a.) git checkout master (this is your LOCAL MASTER)
b.) git pull origin (this will pull updates from your local master with the remote MASTER - Github) - Pulls Origin(remote) and Update (Local)Master
b.) Also try git pull --no-ff (no fast forward)
c.) git checkout 2012Tryme
d.) git merge master (add changes from local master to your local branch)
e. ) MAKE CHANGES. Some conflict may occur on you local branch
d.) git push origin (use this approach. This updates you remote branch)
e.) git push origin master (this approach updates your local master - do not use this approach)
Step C.) Updating your local branch with changes from the GitHUB MASTER and push to repository (Remote Repository)
*********************
git checkout master
git merge origin master
git pull origin master ( use this to pull from your remote MASTER directly)
**********************
Step D.) Updating your local branch with changes from the MASTER and push to repository
*********************
git pull origin master (this will delete your changes and add new master)
git push origin master -ff
git push origin 2012tryme
check git hub to see if repository exit
*********************
MISCELLANEOUS
*****************
DELETING BRANCH ON REMOYTE
Merge Into Master Branch Pull Request
git checkout master
git push origin :branch_name
**********************
Go to github.
a.) Switch branch from MASTER to 2012TRYME
b.) Select Pull Request.
*************************************************
Checking the status of your repository
git status
Seeing what files have been committed
git ls-files
Scheduling deletion of a file
git rm [file name]
Viewing the difference as you commit
git commit -v
*****************************
Viewing a log of your commits
git log
Viewing a log of your commits with a graph to show the changes
git log --stat
Viewing a log with pagination
git log -v
Visualizing git changes
gitk --all
Creating a new tag and pushing it to the remote branch
git tag "v1.3"
git push --tags
Creating a new branch
git branch [name of your new branch]
Viewing branches
git branch
Viewing a list of all existing branches
git branch -a
Switching to another branch
The state of your file system will change after executing this command.
git checkout [name of the branch you want to switch to]
OR
git co [name of the branch you want to switch to]
Making sure changes on master appear in your branch
git rebase master
Merging a branch back into the master branch
First, switch back to the master branch:
git co master
Check to see what changes you’re about to merge together, compare the two branches:
git diff master xyz
If you’re in a branch that’s not the xyz branch and want to merge the xyz branch into it:
git merge xyz
Reverting changes to before said merge
git reset --hard ORIG_HEAD
Resolving conflicts
Remove the markings, add the file, then commit.
Creating a stash (like a clipboard) of changes to allow you to switch branches without committing
git stash save "Put a message here to remind you of what you're saving to the clipboard"
Switching from the current branch to another
git co [branch you want to switch to]
Do whatever
Then switch back to the stashed branch
git co [the stashed branch]
Viewing a list of stashes
git stash list
Loading back the stash
git stash apply
Now you can continue to work where you were previously.
Deleting a branch (that has been merged back at some point)
git branch -d [name of branch you want to delete]
Deleting an unmerged branch
git branch -D [name of branch you want to delete]
Deleting a stash
git stash clear
Setting up a repository for use on a remote server
Copy up your repository. e.g.:
scp -r my_project deploy@yourbox.com:my_project
Move your files on the remote server to /var/git/my_project
For security make the owner of this project git
On the repository server:
sudo chown -R git:git my_project
Then (for security) restrict the “deploy” user to doing git-related things in /etc/passwd with a git-shell.
Checking out a git repository from a remote to your local storage
git clone git@yourbox.com:/var/git/my_project
Viewing extra info about a remote repository
cat .git/config
By virtue of having cloned the remote repository, your local repository becomes the slave and will track and synchronize with the remote master branch.
Updating a local branch from the remote server
git pull
Downloading a copy of an entire repository (e.g. laptop) without merging into your local branch
git fetch laptop
Merging two local branches (ie. your local xyz branch with your local master branch) USE MERGE
git merge laptop/xyz
This merged the (already copied laptop repository’s xyz branch) with the current branch you’re sitting in.
Viewing metadata about a remote repository
git remote show laptop
Pushing a committed local change from one local branch to another remote branch
git push laptop xyz
Creating a tracking branch (i.e. to link a local branch to a remote branch)
git branch --track local_branch remote_branch
You do not need to specify the local branch if you are already sitting in it.
git pull
Note: You can track(link) different local branches to different remote machines. For example, you can track your friend’s “upgrade” branch with your “bobs_upgrade” branch, and simultaneously you can track the origin’s “master” branch (of your main webserver) with your local “master” branch.
By convention, ‘origin’ is the local name given to the remote centralized server which is the way SVN is usually set up on a remote server.
Seeing which local branches are tracking a remote branch
git remote show origin
Working with a remote Subversion repository (but with git locally)
git-svn clone [http location of an svn repository]
Now you can work with the checked out directory as though it was a git repository. (cuz it is)
Pushing (committing) changes to a remote Subversion repository
git-svn dcommit
Updating a local git repository from a remote Subversion repository
git-svn rebase
NOTE: make sure you have your perl bindings to your local svn installation.
I screwed up, how do I reset my checkout?
git checkout -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment