Difference between revisions of "Common Git Actions"

From Gcube Wiki
Jump to: navigation, search
 
Line 19: Line 19:
 
Once the previously discussed "preparing to merge" steps have been taken a merge can be initiated by executing git merge <branch name> where <branch name> is the name of the branch that will be merged into the receiving branch.
 
Once the previously discussed "preparing to merge" steps have been taken a merge can be initiated by executing git merge <branch name> where <branch name> is the name of the branch that will be merged into the receiving branch.
  
The command below integrates the commits from feature/1234 into the current branch (master) with a fast-forward merge.
+
The command below integrates the commits from feature/1234 into the current branch (master) with a fast-forward merge (see [https://git-scm.com/docs/git-merge https://git-scm.com/docs/git-merge]).
  
 
<source lang="bash">
 
<source lang="bash">

Latest revision as of 17:32, 11 June 2019

This page collects some common actions during the interactions with a Git repository.

Using Branch Descriptions in Git

To set or edit the current branch description:

$ git branch --edit-description

This will open your editor so that you can type down the description for whatever branch you’re on. Afterwards whenever you push your branch you will also push the description along with it.

How to Merge a Feature Branch

Make sure the receiving branch and the merging branch are up-to-date with the latest remote changes. Execute git fetch to pull the latest remote commits. Once the fetch is completed ensure the master branch has the latest updates by executing git pull.

$ git fetch
$ git checkout master
$ git pull

Once the previously discussed "preparing to merge" steps have been taken a merge can be initiated by executing git merge <branch name> where <branch name> is the name of the branch that will be merged into the receiving branch.

The command below integrates the commits from feature/1234 into the current branch (master) with a fast-forward merge (see https://git-scm.com/docs/git-merge).

$ git merge feature/1234

There might be conflicts to resolve among the files, but if everything goes well, the next step is to check that the commits are now on master with:

$ git log

The last step is to push the commits to the remote repository:

$ git push origin master

How to contribute to a project via Pull Requests (PR)

  • Fork the upstream repository into a personal one from the Gitea interface
  • Clone the personal repository
  • commit/push to your personal repository, then you are ready to create a *pull request*
  • From the web interface, go to your forked repository page and click on `pull request`
  • From the command line, there is the `git request-pull` command (`git request-pull --help` for details)
  • Or you can use the URL that the git command will output when you `git push`. Something like
remote:
remote: Create a new pull request for 'andrea.dellamico:master':
remote:   https://code-repo.d4science.org/InfraScience/ansible-playbooks/compare/master...andrea.dellamico:master
remote:

The above URL will get you directly to the pull request interface.

How to work on your (forked) repository

1. If you already checked out the upstream and want to work on the fork instead.

$ git remote rename origin upstream
$ git remote add origin YOUR_FORKED_REPOSITORY_URL
$ git fetch origin
$ git branch --set-upstream-to=origin/master master

At this point, your local branch master is tracking the remote branch master of the forked repository.

Make sure that you are on your master branch with:

$ git checkout master

Now you can make your changes and push them to the forked repo with:

$ git push origin

2. If you are starting from a fresh clone of your fork

The private fork must be linked to the upstream one (this command must be executed once):

$ git remote add upstream ORIGINAL_REPOSITORY_URL

Fetch all the branches of upstream into remote-tracking branches, such as upstream/master:

$ git fetch upstream

Make sure that you are on your master branch:

$ git checkout master

Rewrite your master branch so that any commits of yours that aren't already in upstream/master are replayed on top of that other branch:

$ git rebase upstream/master

Last, push to your fork:

$ git push origin master

If you want to to sync all the remote branches, run

$ git remote update

Pull the upstream changes into your forked repository

$ git pull upstream master

Back to the CI guide.