Skip to content

Instantly share code, notes, and snippets.

@rplaurindo
Last active January 10, 2021 04:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rplaurindo/5050417 to your computer and use it in GitHub Desktop.
Save rplaurindo/5050417 to your computer and use it in GitHub Desktop.

Configurations

git config

Proxy

Use global configuration with --global flag.

$ git config --global https.sslBackend openssl

$ git config --global https.sslVerify false

$ git config --global http.proxy http://<user>:<password>@<domain>:<port>

$ git config --global https.proxy https://<user>:<password>@<domain>:<port>

Publishing a new project

In root path of project, run:

Initialize a git project

$ git init

Adding files

$ git add .

Setting the owner user mail

$ git config user.email <email to login in git repository>

Committing with a message

$ git commit -m "a message"

Creating a new origin

$ git remote add <origin> https://<user>:<password>@domain/<user-owner>/<repositoryname>.git

or to SSH authentication

$ git remote add <origin> git@domain-<ssh-filename>:<username>/<repositoryname>.git

Publishing to a remote repository

$ git push -u origin master

Removing a folder or a file

Folder

$ git rm -r <path>

File

$ git rm <path>

Branches

Creating a new

$ git branch <branch>

To create a new branch with only the last commit...

$ git checkout --orphan <branch>

So make git add; git commit...

Change to a branch

$ git checkout <branch>

Creating and changing to a new branch

$ git checkout -b <branch>

Creating a branch through a version

$ git checkout -b <branch> <version>

Showing the current and other branches

$ git branch

Setting up a branch as default to push

$ git branch --set-upstream-to=origin/<branch>

Publishing a project in a new branch

$ git push origin <branch>

Updating the branch

$ git pull --rebase [origin]

In conflict case solve it, after that run:

$ git rebase --skip

If something goes wrong, come back running:

$ git rebase --abort

If you want to merge, just run:

$ git pull

Deleting a remote branch

$ git push --delete origin <branch>

Deleting a local branch

$ git branch -d <branch>

Mixing and updating branches

Branches are importants to organization of the project. When creating a new feature, fixing a bug, or make a refactoring we should do that in a new branch following the below steps:

  • Create a new branch;
  • checkout to this new branch;
  • develop, fix or refactor the code;
  • when you finish, run:
$ git rebase <the more stable (usually) branch>
  • return to more stable branch and run;
$ git merge <the branch of new feature, repair or refactoring>
  • and finally, run:
$ git push

Showing the difference between the lines of files of current branch

$ git diff [file]

Tags

Creating a new tag

$ git tag <value>

Publishing to a remote repository

$ git push origin <tag>

Obs.: tag’s content can’t be changed.

Deleting a local tag

$ git tag -d <tag>

Deleting a remote tag

$ git push --delete origin <tag>

Discarding a local commit

$ git reset --hard HEAD~1

Reverting a commit

$ git revert <"HEAD" or commit hash>
$ git push

Contributing to a project that you don't keep

  • Clone the project;
  • create a new origin;
  • create and checkout to a new branch;

When you finish:

  • Commit the changes;
  • checkout to main branch;
  • make "rebase" from branch you worked for;
  • push.

Ready. Now just do "Pull Request" through main branch.

Updating from remote repository

$ git fetch <origin>
$ git rebase <origin>/<branch>

Sources:

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