Skip to content

Instantly share code, notes, and snippets.

@rplaurindo
Last active August 9, 2024 14:32
Show Gist options
  • 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 <branchname>

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

$ git checkout --orphan <branchname>

So make git add; git commit...

Change to a branch

$ git checkout <branchname>

Creating and changing to a new branch

$ git checkout -b <branchname>

Creating a branch through a version

$ git checkout -b <branchname> <version>

Showing the current and other branches

$ git branch

Setting up a branch as default to push

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

Publishing a project in a new branch

$ git push origin <branchname>

Updating a branch

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.

To merge the changes from a remote repository, just run:

$ git pull

Using git rebase

To update local changes, setup the branch you want to update, and run:

$ git rebase <from-branchname>

In conflict case solve it (you must to commit the changes), so run:

$ git rebase --continue

So solve the next conflict. If there are no new conflicts, commit and push the new changes to remote repository.

If something goes wrong, come back running:

$ git rebase --abort

Using git cherry-pick

$ git cherry-pick <commit-hash OR branch-name> --no-commit

So just run $ git push.

Note: to put a interval, run $ git cherry-pick <commit-hash-START>..<commit-hash-END>.

Deleting a remote branch

$ git push --delete origin <branchname>

Deleting a local branch

$ git branch -d <branchname>

Showing the difference between the lines of files of current branch

$ git diff <filename>

Tags

Creating a new tag

$ git tag <value>

Publishing to a remote repository

$ git push origin <tag>

Note: 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;
  • ceate a new origin;
  • create and checkout to a new branch;

When you finish:

  • commit the changes;
  • checkout to main branch;
  • update the main branch from branch you worked for;
  • make "Pull Request" through main branch.

Sources:

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