Rebase : don't forget to git add . and git commit -m 'commit to be able to rebase' before reset main (in case you haven't worked in a branch before)
git reset --hard main
https://github.com/taniarascia/git https://gist.github.com/jedmao/5053440 https://github.github.com/training-kit/downloads/github-git-cheat-sheet.pdf https://guides.github.com/
idea : gitflow , alias, flow pour d'autre feature https://guides.github.com/
- on master branch
- git checkout -b new-branch
or git branch XXX # create branch and then git checkout XXX
- (code the new feature)
- git add .
- git commit -m 'message'
- git push origin new-branch
- go on github
- create pull request
- ask your teammates to review the code
- once everyone is happy merge new-branch with master
- git checkout master
- git pull origin master
- git sweep
- repeat
- it's far easier to debug github issues when you are in a branch and not on the master so :
- never commit on master (always use a branch to be sure)
- never push on master otherwise your techlead will kill you
- use branches : it's a place where you can do everything you want ! your play around, as many commit as possible etccc !
$ hub browse
$ clear
cmd + k
$ history
control + c
1. Never pull on the MASTER BRANCH
2. Don’t merge yourself unless 1000% sure : Lead programmer closes your PR (merges your changes to remote master). But you’re not done yet!
alias gs='git status'
alias ga='git add'
alias gaa='git add .'
alias gc='git commit -m'
alias gm='git push origin master'
alias cr='clear'
alias rs='rails s'
alias dd='rails db:drop'
alias dc='rails db:create'
alias dm='rails db:migrate'
alias ds='rails db:seed'
alias da='rails db:drop db:create db:migrate db:seed'
alias rc='rails c'
alias rr='rails routes'
alias gb = 'git branch'
alias gco = 'git checkout'
alias gcob = 'git checkout -b'
alias gcom='git checkout master'
alias gd='git diff'
alias gi='git init'
alias glg='git log --graph --oneline --decorate --all'
alias gp='git push origin'
alias gl='git pull origin'
alias pom = 'git push origin master'
alias puom = 'git pull origin master'
alias gpo='git push origin HEAD'
alias gbr='git branch -m'
alias ga='git add'
alias gaa='git add .'
alias gaaa='git add --all'
alias gau='git add --update'
alias gb='git branch'
alias gbd='git branch -D'
alias gc='git commit'
alias gcm='git commit --message'
alias gcf='git commit --fixup'
alias gco='git checkout'
alias gcam='git commit -am'
alias gt='git checkout -'
alias gcob='git checkout -b'
alias gcom='git checkout master'
alias gcos='git checkout staging'
alias gcod='git checkout develop'
alias gd='git diff'
alias gda='git diff HEAD'
alias gi='git init'
alias glg='git log --graph --oneline --decorate --all'
alias gld='git log --pretty=format:"%h %ad %s” --date=short --all"'
alias gm='git merge'
alias gma='git merge --abort'
alias gmc='git merge --continue'
alias gp='git pull'
alias gpr='git pull --rebase'
alias gr='git rebase'
alias gs='git status'
alias gss='git status --short'
alias gst='git stash'
alias gsta='git stash apply'
alias gstd='git stash drop'
alias gstl='git stash list'
alias gstp='git stash pop'
alias gsts='git stash save'
alias grh='git reset --hard HEAD'
alias gls="git for-each-ref --sort=-committerdate refs/heads/ --format='%(authordate:short) %(color:red)%(objectname:short) %(color:yellow)%(refname:short)%(color:reset) (%(color:green)%(committerdate:relative)%(color:reset))'"
alias ytbr="yarn tag-build-ready"
alias yd='yarn dev'
alias yyd='yarn && yarn dev'
alias ys='yarn start'
alias yt='yarn testn'
alias yst='yarn staticCheck'
alias ybys='yarn build && yarn start'
alias yf='yarn flow'
alias np='npm publish'
alias nptb='npm publish --tag beta'
aim idea here is to find a solution in order
to block git push origin master or the same with -f
i.e to protect from all dangerous commands
or how to run command in order to block kind of command
and returning a string or adding a [Y/N] or password ???
alias slk="open -a 'slack'"
alias crm="open -a 'Google Chrome'"
-
$ mkdir PROJECT-NAME
-
$ cd PROJECT-NAME
- $ git init
- $ hub create
- $ git remote -v
You should get someting like :
origin git@github.com:GITHUB_USERNAME/PROJECT-NAME.git (fetch)
origin git@github.com:GITHUB_USERNAME/PROJECT-NAME.git (push)
-
$ git pull origin master
-
$ git add .
-
$ git commit -m "initialize the repository"
-
$ git push origin master
- $ git status
- $ mkdir ~/code/OWNER_GITHUB_USERNAME
- $ cd ~/code/OWNER_GITHUB_USERNAME
- $ git clone git@github.com:OWNER_GITHUB_USERNAME/PROJECT_NAME.git
- $ cd PROJECT_NAME
$ git diff
$ git diff
Show all commits, starting with newest (it'll show the hash, author information, date of commit and title of the commit):
$ git log
- Fork any open source GitHub repo you want
- Clone that repo in your PC :
git clone https://github.com/YOUR-GITHUB-NAME/NAME-REPO-YOUR-FORKED
- Make changes and commit/push these changes from your terminal :
git add .
git commit -m " My change for this repo"
git push
- Go to your fork, click open
Pull Request
link and create a PR : Add a relevant description to comment your code 👌!
If you want to improve this repository, follow these steps (work with all repository you don't own but you want to change) :
- Fork it ( https://github.com/PelDoingCode/git_cheat_sheet/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature') - try to include tests
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
- $ git commit
- $ git push
- LEAVE BUILDING
- In the directory you cloned the repository, run git fetch --all
- Use git checkout BRANCH_NAME -f to jump into a given branch. The -f will force overwriting your local changes
1/ Do git reset HEAD^ for as many commits you want to undo, it will keep your changes and your actual state of your files, just flushing the commits of them.
2/ Once the commits are undone, you can think about how to commit your files in a better way, e.g.: removing/ignoring the huge files and then adding what you want and then committing again. Or use Git LFS to track those huge files.
Usefull links :
https://stackoverflow.com/questions/20002557/how-to-remove-a-too-large-file-in-a-commit-when-my-branch-is-ahead-of-master-by
https://stackoverflow.com/questions/9529078/how-do-i-use-git-reset-hard-head-to-revert-to-a-previous-commit#targetText=HEAD%20points%20to%20your%20current,log%20or%20any%20history%20browser
https://stackoverflow.com/questions/20002557/how-to-remove-a-too-large-file-in-a-commit-when-my-branch-is-ahead-of-master-by
https://stackoverflow.com/questions/927358/how-do-i-undo-the-most-recent-local-commits-in-git
⚠️ before doing a "git push origin master" always PULL ! run :
git pull origin master
Otherwise you will outwrite the master !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ga .
gc 'force to push in case of emergency'
git push origin master -f
ps : you can push on an other branch than master also
git fetch --all
git reset --hard origin/master
ps : you will force what you have on master to be on local
If you like this project, feel free to donate:
- PayPal:
- Bitcoin:
Please ⭐️ this repository if this project helped you, don't hesitate to reach me on Linkedin !