Skip to content

Instantly share code, notes, and snippets.

@rogeralbp
Last active January 23, 2022 20:09
Show Gist options
  • Save rogeralbp/a6391e3907dcba903e95559bd3085eed to your computer and use it in GitHub Desktop.
Save rogeralbp/a6391e3907dcba903e95559bd3085eed to your computer and use it in GitHub Desktop.
Important things of Git by @rogeralbp

Table of Contents

Git Definitions

Commands

Aliases

Creating a Repository

Creating a Release Tag

Git Tags

  • Reference to state of the project in a specific commit
  • The tags are useful as Referenced Points
  • Are used to have more valuable git history
  • Are commonly for the versions of a product, example : v1.0.0

Fastforwarding and Recursive - Merge Context

  • Fastforwarding: this happend when the branch that will receive the changes DO NOT have any recently changes the merge will be a success

  • Recursive: this happend when the branch that will receive the changes HAVE recently changes but it will not a problem at the merge process

  • HEAD: Last commit(code changes point) where the current branch is.

Update Remote References of the Repository

git fetch

Push Tags to the repository

git push --tags

Rebase

When a main (parent) branch has been updated and this changes are neccesary at all the child branches this works to pull those changes to the child branch and minimize the possible conflicts


git checkout childBranch

and then ...

git rebase mainBranch


List all Tags

 git tag

List all the metadata of a Specific Tag

 git show nameTag

Create a Tag

This Tag it will be referenced to the last commit

 git tag nameTag

Create a Tag to a Specific Commit

This Tag it will be referenced to a Specific commit

 git tag -a nameTag shortCommitHash -m "MessageCommit"

Remove a Tag

 git tag -d nameTag

and then update all local 
and remote references

  git remote prune origin

List the local branches of the Project

git branch

List all branches of the Project

first step :
git fetch

second step :
git branch

Create a branch

git branch nameBranch

Delete a Branch

this is important to after the branch accomplish his purpose

git branch -d nameBranch

Force the delete of a Branch

git branch -d nameBranch -f

Create a branch and switch to there

git checkout -b nameBranch

Switch to a Branch

git checkout nameBranch

Rename a branch

Once you are at the branch that it will be renamed

git branch newBranchName

Merge of branch

Once you are at the branch that will receive the changes(main branch)

git merge brancWithChanges

List summarized of the most important commands to use Git by @rogeralbp

Change the global config of Git

git config --global -e 
 

Initialize a folder as Repository

git init
 

Review (stage) what files were updated and what files were not

(ready to commit and then push)

git status

Add files to Stage Area previous to Snapshot Zone

git add .

Commit the what files were updated and why

this happend when a developer makes an important change that could be historic

git commit -m "AAAAAAAAAAA"

Rebuild the Project as the last version commited (last commit)

git checkout -- . | git reset --hard commitShorHash

Rename Branch

git branch -m currentName newName

git add and git commit in ONE step (only works with tracked files)

git commit -am "AAAAAAAAAAAAAA"

Logs Register of Commits

git log

Adding to Stage Area using a filter of files

git add *.html | *.js | *.css | etc....

Checkout what are the recently changes

this works before the files were added yo the staging area

git diff

Update the description of a Commit

this command is useful ti change the description of the last commit

git commit --amend -m "DescriptionUpdated"

Rebuild the project to a specific version by his commit

in this command the short hash of the command is important

git reset --hard shortHast

example:

git reset --hard 85151asj

example

Review ALL the logs of the Project

git reflog

Rename a file by command

Useful for make changes and saving in the History Git

git mv currentName.ext newName.ext

ext = .md, .js, .html, etc...

Remove a file by command

Useful for make changes and saving in the History Git

git rm file.ext 

.gitignore File

Useful for do not make the corresponding following of folders and files:

  • Need to be in the home (raiz) of the project
  • Inside of this file needs to be the name of those folders and files
  --.gitignore
     --dist/
     --holamundo.html
     --app.js
     --profilesimgs/
     --*.css
     --*.log

The Aliases are useful to reduce the inverted time typing a command to execute

How to Create a Alias

git config --global alias.aliasName function *flags

example:

git config --global alias.s status --short

aliasName = the symbol, letter
function  = the action (commit, push , pull, status)
flags     = Optional flag for the Alias 

Personal Aliases of @rogeralbp

Access to global aliases

git config --global -e
- Short Description of the Status:
git config --global alias.s status --short --branch

- Short and useful metadata of the Logs:
git config --global alias.log "log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all"

1 - First steps after creating the Repository

image

2 - Useful Metadata of the Repository

image

3 - Remote Metadata

image

These are possible versions to download

1 - Go to the Releases Section complete the inputs (metadata)

image

2 - Pre Release Option

this is useful when a release is not completed to use already

image

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