-
Notifications
You must be signed in to change notification settings - Fork 0
Git Commands
Andrew Colbeck edited this page May 6, 2019
·
9 revisions
Command | Description |
---|---|
git checkout <mybranch> |
If not already in your branch, checkout |
git fetch origin |
gets you up to date with origin |
git merge origin/master |
merge changes stored in master branch with this |
Command | Description |
---|---|
git init |
Initialise the Folder as a Github Repo |
git add . |
Stage All Files ready for commit |
git commit -m "First commit" |
Commit the staged files ready for pushing to remote branch |
git remote add origin remote repo URL
|
Add the repo's URL as the origin for the branch |
git remote -v |
Verifies the URL with a fetch packet |
git push -u origin master |
Pushes the commited files |
Command | Description |
---|---|
git clone remote repo URL
|
Create a local copy of a Repo |
git status |
Show which locally stored files have changed since last commit |
git diff |
Show the actual lines of code per file that are different from the remote |
git add -a |
Stages all local files that are different ready to be committed |
git checkout filename
|
Restore the file, deleting locally saved changes |
git commit -m "Message"
|
Adds a message to the staged commit |
git log |
Show a log of Commits |
git log --stat |
Show each Commit in detail (additions, removed files etc.) |
git commit --amend -m "Updated Message"
|
Amends the previous commit message, and adds any new files/changes |
git commit --amend |
Adds new files/changes to the previous commit |
git touch .gitignore |
Creates a local .gitignore file in the directory |
git stash |
Temporarily store current changes on a Stack |
git stash pop |
Pop the stashed changes into the working directory (after stashing) |
git rm -r --cached file.txt |
Remove a File from being tracked |
git rm -r --cached bin/ |
Remove a Folder from being tracked |
git rm -r --cached . |
Remove all files from being tracked |
mv [file name] ~/.Trash |
Move a file to the trash |
rm file.txt |
Delete a File (permanently deleted, this file will NOT be in the recycling bin) |
rmdir folder/ |
Delete a Folder (permanently deleted, this file will NOT be in the recycling bin) |
Command | Description |
---|---|
git checkout -b <branch_name> |
Create a new branch and checkout |
git branch |
Show all branches (highlighting the current branch working on) |
git checkout branchname
|
Switches to a different branch |
git log |
Show commit history for this branch |
git cherry-pick first 8 digits of commit hashcode
|
Brings in the other branch's commit into this one |
git reset --soft first 8 digits of commit hashcode
|
Resets branch back to the hash's commit, but keeps changes in the staging directory |
git reset first 8 digits of commit hashcode
|
Resets branch back to the hash's commit, but leaves changes in the working directory (changes have to be added with git add -a ) |
git reset --hard first 8 digits of commit hashcode
|
All changes are deleted, local repo is reverted back to the specified commit |
git clean -df |
Removes all new 'Directories' and 'Files' from local repo (so that it matches the hard resetted commit) |
git reflog |
Show all commit history. To bring a deleted/lost branch back: git checkout hashcode, then git branch backup to save it. |
git revert first 8 digits of commit hashcode
|
Reverts back to that commit, doesn't delete the commit history. |
git diff hashcode1 hascode2
|
Shows differences between the secified commits |
Command | Description |
---|---|
I | Enter INSERT TEXT Mode |
Esc | Exit Edit Mode |
:wq |
'Write' changes, and 'Quit' |
:q! |
'Quit' the Document without (!)saving |