Wiki

Clone wiki

DevFecta Public Repository / Git Cheat Sheet

Setup SSH

NOTE: In Bitbucket the SSH Key should be adding under the user account, not the team or repository.

In the home directory ~/ enter:

ssh-keygen
Hit enter for the default id_rsa file in the .ssh directory, and it will be stored here: /home/<username>/.ssh/id_rsa.pub

Add the key to the ssh-agent so you don't have to type the password each time you use the key:

eval `ssh-agent`

ssh-add ~/.ssh/id_rsa.pub

cat ~/.ssh/id_rsa.pub <-- to view and copy the contents of the id_rsa.pub file for Bitbucket.

git pull <-- Pull everything
git pull <branch>
git add *
git add <filename>
git commit -m "<message>"
git commit -am "<message>" <-- commits with add function and removes deleted local files from repository.
git push <-- Push everything
git push <branch> <-- Pushes a specific branch

Branching Commands

Branching A Repository

After the repository is cloned:

git checkout -b <new branch name> <-- Creates the branch locally and switches the local repository to the new branch.

git push origin <new branch name> <-- Creates the branch on the remote

git branch -a <-- View branches and the starred branch is the one you are using.

git commit -m "<message>"

git push -u origin <new branch name> <-- Sends files to the new branch.

BitBucket Settings

Remove the window prompt.

git config --global --replace-all credential.interactive false
git config --global --replace-all credential.modalPrompt false

Resetting Changes Locally

Reset an Add

Removes a file from staging after an "add".

git reset filename.txt
Removes all files from staging after an "add".
git reset

Reset a Commit

Undos the last commit and preserves the changes to your files.

git reset --soft HEAD~1
Reverts back to your last commit.
git reset --hard HEAD~1
NOTE: You may want to do a "pull" after a hard reset.

Tagging Commands

Tagging A Repository

git tag -a <tag name> -m "<tag description>"

Push Tags to Remote Repository

git push origin --tags

Deleting Tags

Delete Remote Tag

git push --delete origin <tag name>

Delete Local Tag

git tag -d <tag name>

Updated