Skip to content

Instantly share code, notes, and snippets.

@Snake-Sanders
Last active February 21, 2019 15:12
Show Gist options
  • Save Snake-Sanders/828a1648957bdf6ad26afc427164b105 to your computer and use it in GitHub Desktop.
Save Snake-Sanders/828a1648957bdf6ad26afc427164b105 to your computer and use it in GitHub Desktop.
Git cheat-sheet

Set a directory as a git repo

git init

Stage files to be committed

git add .

Commit files to local database

git commit . -m "added new files to my commit"

See what was not tracked=? modified=M staged=A and committed

git status

To merge your previous commit to the next one, only for editing the commit msg

git commit --amend

Revert changes to a file that was modified but not staged

git checkout -- myFile.c
git checkout -- .

Unstage a file

git reset [file_name]

Search a string among the commits

git log -S text_to_find

Rename a file

$ git mv file_from file_to

Remove a file

rm myFile.txt
git rm myFile.txt

Remove a modified file

git rm -f myFile.txt

Show remote servers

git remote -v

Branches

Create a branch

git branch branch_name

Change branch

git checkout branch_name

Show branches log

git log --oneline --decorate --graph --all

Merge a branch back to master

git checkout master
git merge branch_name

Delete a branch

git branch -d branch_name

Updating your branch with the latest changes in the master

git checkout feature
git rebase master

or if you want an extra commit use:

git checkout feature
git merge master

or in one line:

git merge master feature

Create a branch based on your local changes done on the master branch

git checkout -b new_branch_name

Merge conflicts:

<<<<<<< HEAD:
Here are shown the changes done in the current branch.
The branch you are runnign the merge command
========
Here are shown the changes done in the branch you are importing
>>>>>>>>

To fix the conflict edit manually the file and delete the delimiters To resolve the coflic use:

git add
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment