Git Cheat Sheet

ADVERTISEMENT

15-441
GIT Cheat Sheet
Harshad Shirwadkar
CREATE
MERGE
Creating a Git repository
Merging branch-new into branch-master
 
- ​
$ git init
# # Initializes git inside the pwd
$ git checkout branch​
m aster
#
- ​
$ git merge branch​
n ew
#
## Review and fix conflicts if any and commit​
#
Creating a remote
## changed files.
#
#
​ O R ​
## Create a repo on Github / bitbucket
#
## Use AFS as follows
#
TAGS
## Create a folder for your repository in AFS​
#
Create a tag
## Give access rights to your partner:
#
$ fs setacl ​
. ​
< ​
$ git tag ​
< ​
- ​
p artner​
' s-andrewid> rlidwk
#
t ag​
n ame>
#
## Create a remote in current dir
#
 
$ git init ​
- -​
b are
#
#
List tags
 
$ git tag ​
- l
#
Cloning from Remote
$ git clone ​
Delete a tag
< url>
#
## For afs, the URL looks like:
#
$ git tag ​
- ​
d ​
< ​
- ​
t ag​
n ame>
#
## ​
: /afs/.../p2 ​
a ndrewid@linux.andrew.cmu.edu​
#
## For github / bitbucket, the URLs are
#
UNDO
## provided on the repo page. E.g.,
#
#
Discard all local changes in your working
## ​
g it@github.com​
: githubname/repo.git
#
directory (!!!)
$ git reset ​
- -​
h ard HEAD
#
Adding Remote named “origin” to the Local
Repository
Discard local changes in a specific file
 
$ git remote add origin ​
< url>
#
(!!!)
$ git checkout HEAD ​
< filename>
#
COMMITS
 
Committing your changes
Revert a commit by creating a new UNDO commit
$ git add ​
< files>​
# # Add files for committing
$ git revert ​
< commit>
#
$ git commit ​
- ​
m ​
" meaningful commit message”
#
 
 
Reset repository to a previous commit and
Pushing to a remote named “origin”
discard all the changes since then (!!!)
 
$ git push origin ​
$ git reset ​
h ard ​
< branch>
#
- -​
< commit>
#
 
 
Reset repository to a previous commit and
Pulling from a remote named “origin”
preserve changes since then as unstaged
 
$ git pull origin ​
< branch>
#
$ git reset ​
< commit>
#
 
 
BRANCHES
STATUS AND HISTORY
Creating a branch named branch-new
Show changed files since last commit
 
- ​
$ git branch branch​
n ew
# #
$ git status
#
 
Switching to a branch named branch-new
Show commit history
- ​
$ git checkout branch​
n ew
#
$ git log
#

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go