Last active
February 14, 2020 12:10
-
-
Save sodogan/ad50880bbefce2ce2691d37f9166c1aa to your computer and use it in GitHub Desktop.
GIT BASH CHEAT SHEET COMMANDS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Common console commands: | |
cd - change directory | |
mkdir - make directory | |
ls - view the files/folders in directory | |
rm -r -to delete dirs or files | |
NOTE: Exit VIM if needed ctrl + c then type :qa! and push enter | |
NOTE: If file is not in local repo, manually move the file into | |
the correct folder (outside of console) | |
-------------------------------------------- | |
Managing your Local Repo | |
-------------------------------------------- | |
NOTE: If you need to hard reset your local repo to match | |
the remote master use the following commands: | |
$ git fetch origin | |
$ git reset --hard origin/master | |
Undo the act of committing, leaving everything else intact: | |
$ git reset --soft HEAD^: | |
Undo the act of committing and everything you'd staged, | |
but leave the work tree (your files intact): | |
$ git reset HEAD^ | |
Completely undo it, throwing away all uncommitted changes, | |
resetting everything to the previous commit: | |
$ git reset --hard HEAD^ | |
-------------------------------------------- | |
WORKFLOW FOR LOCAL REPOSITORY | |
-------------------------------------------- | |
Bare vs. cloned repositories | |
If you used git clone in the previous "Initializing a new Repository" section to set up your local repository, | |
your repository is already configured for remote collaboration. | |
git clone will automatically configure your repo with a remote pointed to the Git URL you cloned it from. | |
This means that once you make changes to a file and commit them, | |
you can git push those changes to the remote repository. | |
If you used git init to make a fresh repo, you'll have no remote repo to push changes to. | |
So Need to configure: | |
git config --global user.name <name> | |
git config --local user.email <email> | |
Example: | |
$ mkdir test | |
$ cd test | |
$ git init | |
Initialized empty Git repository in /Users/solendogan/Documents/test_git/test/.git/ | |
$ echo "first change" >> first.txt | |
$ git add . | |
$ git commit -m "added the first change" | |
Then set the remote destination: | |
git remote add <remote_name> <remote_repo_url> | |
Example: git remote add origin https://github.com/sodogan/test_git.git | |
and then push using the remote name | |
git push <remote_name> as above it will be git push origin | |
-------------------------------------------- | |
WORKFLOW FOR EXISTING REPOSITORY | |
-------------------------------------------- | |
Clone the Repo to local machine: | |
$ git clone https://github.com/user_name/repo_name.git | |
Make sure the local master is up-to-date: | |
$ git pull origin master | |
Create new branch: | |
$ git banch branch_name | |
Move to branch: | |
$ git checkout branch_name | |
Navigate file structure as needed: | |
$ ls | |
$ cd folder_name | |
Add the files to the branch: | |
$ git add . | |
Verify file: | |
$ git status | |
Commit the files: | |
$ git commit -m "comment" | |
Add branch and files to the Remote Repo: | |
$ git push -u origin branch_name | |
Go to the github website to manage pull request and merge. | |
Switch back to local master so you can delete the local branch: | |
$ git checkout master | |
Delete local branch: | |
$ git branch -d branch_name | |
OR | |
$ git branch -D branch_name | |
If you don't want to go to the website, you can merge your branch | |
to the master locally and push the new master to the remote repo: | |
Switch back to master branch: | |
$ git checkout master | |
Merge the branch with the local master: | |
$ git merge branch_name -m "comment" | |
Push the local master to the remote master: | |
$ git push origin master | |
Delete local branch: | |
$ git branch -d branch_name | |
OR | |
$ git branch -D branch_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment