Git: Difference between revisions

From HaFrWiki42
Jump to navigation Jump to search
Line 112: Line 112:
== Github flow ==
== Github flow ==
At GitHub, we use our products every day and have developed a workflow to collaborate on projects.  
At GitHub, we use our products every day and have developed a workflow to collaborate on projects.  
To make it work for teams regardless of their size or technical expertise, we made sure each step in our workflow can be completed within a web-based interface. <ref>[https://help.github.com/articles/github-flow GitHub Articles], Help-GitHub-Flow</ref><ref>[https://guides.github.com/introduction/flow Guides-GitHub] Flow Guides</ref>
To make it work for teams regardless of their size or technical expertise, we made sure each step in our workflow can be completed within a web-based interface. <ref>[https://help.github.com/articles/github-flow Help-GitHub Articles], Help-GitHub-Flow</ref><ref>[https://guides.github.com/introduction/flow Guides-GitHub] Flow Guides</ref>
# [[#Create_a_branch|Create a branch]] from the repository.
# [[#Create a branch| Create a branch]] from the repository, [[#Delete a branch|Delete a branch]] from the repository. <ref>[https://help.github.com/categories/managing-files-in-a-repository Help-GitHub Categories], Managing Files.</ref>
# [[#Create, edit, rename, move, or delete|Create, edit, rename, move, or delete]] files.
# [[#Create file|Create]], [[#Edit file|edit]], [[#Rename file|rename]], [[#Move file|move]], or [[#Delete file|delete] files.
# [[#Send a pull request|Send a pull request]] from your branch with your proposed changes to kick off a discussion.
# [[#Send a pull request|Send a pull request]] from your branch with your proposed changes to kick off a discussion.
# [[#Make changes|Make changes]] on your branch as needed. Your pull request will update automatically.
# [[#Make changes|Make changes]] on your branch as needed. Your pull request will update automatically.
Line 121: Line 121:


=== Create a branch ===
=== Create a branch ===
# On GitHub, navigate to the main page of the repository.
# Click the branch selector menu.
# Type a unique name for your new branch.
# Press Enter.
=== Delete a branch ===
# On GitHub, navigate to the main page of the repository.
# Above the list of files, click  NUMBER branches.
# Scroll to the branch that you want to delete, then click the trash-bin.


=== Create, edit, rename, move, or delete ===
=== Create, edit, rename, move, or delete ===
{| class="wikitableharm" width="100%"
|-
| width="20%" |
==== Create file ====
| width="20%" |
==== Edit file ====
| width="20%" |
==== Rename file ====
| width="20%" |
==== Move file ====
| width="20%" |
==== Delete file ====
|- style="vertical-align:top;"
|
# On GitHub, navigate to the main page of the repository.
# In your repository, browse to the folder where you want to create a file.
# Above the file list, click Create new file.
# In the file name field, type the name and extension for the file. To create subdirectories, type the / directory separator.
# On the Edit new file tab, add content to the file.
# To review the new content, click Preview.
# At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file.
# Below the commit message fields, decide whether to add your commit to the current branch or to a new branch. If your current branch is master, you should choose to create a new branch for your commit and then create a pull request.
# Click Propose new file.
[https://help.github.com/articles/creating-new-files More...]
|
# In your repository, browse to the file you want to edit.
# In the upper right corner of the file view, click the pencil-icon to open the file editor.
# On the Edit file tab , make any changes you need to the file.
# Above the new content, click Preview changes.
# At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file.
# Below the commit message fields, decide whether to add your commit to the current branch or to a new branch. If your current branch is master, you should choose to create a new branch for your commit and then create a pull request.
# Click Propose file change.
[https://help.github.com/articles/editing-files-in-your-repository More...]
|
# In your repository, browse to the file you want to rename.
# In the upper right corner of the file view, click the pencil-icon to open the file editor.
# In the filename field, change the name of the file to the new filename you want. You can also update the contents of your file at the same time.
# At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file.
# Below the commit message fields, decide whether to add your commit to the current branch or to a new branch. If your current branch is master, you should choose to create a new branch for your commit and then create a pull request.
# Click Propose file change.
[https://help.github.com/articles/renaming-a-file More...]
|
# In your repository, browse to the file you want to move.
# In the upper right corner of the file view, click the pencil-icon to open the file editor.
# In the filename field, change the name of the file using these guidelines:
#* To move the file into a subfolder, type the name of the folder you want, followed by /. Your new folder name becomes a new item in the navigation breadcrumbs.
#* To move the file into a directory above the file's current location, place your cursor at the beginning of the filename field, then either type ../ to jump up one full directory level, or type the backspace key to edit the parent folder's name.
# At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file.
# Below the commit message fields, decide whether to add your commit to the current branch or to a new branch. If your current branch is master, you should choose to create a new branch for your commit and then create a pull request.
# Click Propose file change.
[https://help.github.com/articles/moving-a-file-to-a-new-location More...]
|
# Browse to the file in your repository that you want to delete.
# At the top of the file, click the 'Trash-bin'.
# At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file.
# Below the commit message fields, decide whether to add your commit to the current branch or to a new branch. If your current branch is master, you should choose to create a new branch for your commit and then create a pull request.
# Click Propose file change.
|}


=== Send a pull request ===
=== Send a pull request ===
See https://help.github.com/articles/about-pull-requests
=== Make changes ===
=== Make changes ===
Just do the necessary changes.
=== Merge ===
=== Merge ===
See https://help.github.com/articles/merging-a-pull-request
=== Tidy up ===
=== Tidy up ===
See https://help.github.com/articles/deleting-and-restoring-branches-in-a-pull-request


== See also ==
== See also ==

Revision as of 16:32, 26 June 2017

Git [1], is a distributed revision control and source code management (SCM) system with an emphasis on speed. Initially designed and developed by Linus Torvalds for Linux kernel development, Git has since been adopted by many other projects. Every Git working directory is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server.

Stages

This is the main thing to remember about Git if you want the rest of your learning process to go smoothly. Git has three main states that your files can reside in:

  • Committed,
    Committed means that the data is safely stored in your local database.
  • Modified,
    Modified means that you have changed the file but have not committed it to your database yet.
  • Staged,
    Staged means that you have marked a modified file in its current version to go into your next commit snapshot.

This leads us to the three main sections of a Git project: the Git directory, the working directory, and the staging area.

  • Git directory
    The Git directory is where Git stores the metadata and object database for your project. This is the most important part of Git, and it is what is copied when you clone

a repository from another computer.

  • Working directory
    The working directory is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for

you to use or modify.

  • Staging area
    The staging area is a simple file, generally contained in your Git directory, that stores information about what will go into your next commit. It’s sometimes referred to as the index, but it’s becoming standard to refer to it as the staging area.

The basic Git workflow goes something like this:

  1. Modify files in your working directory.
  2. Stage the files, adding snapshots of them to your staging area.
  3. Commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.

Setup

To setup git [2]

Username

First you need to tell git your name, so that it can properly label the commits you make.

 # Sets the default name for git to use when you commit.
 $ git config --global user.name "harm"

Email

Git saves your email address into the commits you make. We use the email address to associate your commits with your GitHub account.

 # Sets the default email account for git when you commit
 $ git config --global user.email "h.frielink@<you-server-name>"

Cheat Sheet

Always handy are Cheat Sheets [3].

Information  
Status Repo git status    


Create & Clone Add & Remove
Create new repo git init Add changes to INDEX git add <filename>
Clone local repo git clone /path Add all changes to INDEX git add *
Clone remote repo git clone username@host:/path/to/repo Remove / Delete git rm <filename>


Commit & Synchronize Branches
Commit changes git commit -m "Message" Create new branch git checkout -b <branch>
i.e.: git checkout feature-x
Push changes to remote repo git push origin master Switch to master branch git checkout master
Connect local repo to remote repo git remote add origin <server> Delete branch git branch -d <branch>
Update local repo with remote changes git pull push branch to remote repo git push origin <branch>


Merge Tagging
Merge changes from another branch git merge <branch> Create tag git tag <tag> <commit-ID>
View changes between 2 branches git diff <src-branch> <trg-branch> Get commit IDs git log

Github flow

At GitHub, we use our products every day and have developed a workflow to collaborate on projects. To make it work for teams regardless of their size or technical expertise, we made sure each step in our workflow can be completed within a web-based interface. [4][5]

  1. Create a branch from the repository, Delete a branch from the repository. [6]
  2. Create, edit, rename, move, or [[#Delete file|delete] files.
  3. Send a pull request from your branch with your proposed changes to kick off a discussion.
  4. Make changes on your branch as needed. Your pull request will update automatically.
  5. Merge the pull request once the branch is ready to be merged.
  6. Tidy up your branches using the delete button in the pull request or on the branches page.

Create a branch

  1. On GitHub, navigate to the main page of the repository.
  2. Click the branch selector menu.
  3. Type a unique name for your new branch.
  4. Press Enter.

Delete a branch

  1. On GitHub, navigate to the main page of the repository.
  2. Above the list of files, click NUMBER branches.
  3. Scroll to the branch that you want to delete, then click the trash-bin.

Create, edit, rename, move, or delete

Create file

Edit file

Rename file

Move file

Delete file

  1. On GitHub, navigate to the main page of the repository.
  2. In your repository, browse to the folder where you want to create a file.
  3. Above the file list, click Create new file.
  4. In the file name field, type the name and extension for the file. To create subdirectories, type the / directory separator.
  5. On the Edit new file tab, add content to the file.
  6. To review the new content, click Preview.
  7. At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file.
  8. Below the commit message fields, decide whether to add your commit to the current branch or to a new branch. If your current branch is master, you should choose to create a new branch for your commit and then create a pull request.
  9. Click Propose new file.

More...

  1. In your repository, browse to the file you want to edit.
  2. In the upper right corner of the file view, click the pencil-icon to open the file editor.
  3. On the Edit file tab , make any changes you need to the file.
  4. Above the new content, click Preview changes.
  5. At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file.
  6. Below the commit message fields, decide whether to add your commit to the current branch or to a new branch. If your current branch is master, you should choose to create a new branch for your commit and then create a pull request.
  7. Click Propose file change.

More...

  1. In your repository, browse to the file you want to rename.
  2. In the upper right corner of the file view, click the pencil-icon to open the file editor.
  3. In the filename field, change the name of the file to the new filename you want. You can also update the contents of your file at the same time.
  4. At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file.
  5. Below the commit message fields, decide whether to add your commit to the current branch or to a new branch. If your current branch is master, you should choose to create a new branch for your commit and then create a pull request.
  6. Click Propose file change.

More...

  1. In your repository, browse to the file you want to move.
  2. In the upper right corner of the file view, click the pencil-icon to open the file editor.
  3. In the filename field, change the name of the file using these guidelines:
    • To move the file into a subfolder, type the name of the folder you want, followed by /. Your new folder name becomes a new item in the navigation breadcrumbs.
    • To move the file into a directory above the file's current location, place your cursor at the beginning of the filename field, then either type ../ to jump up one full directory level, or type the backspace key to edit the parent folder's name.
  4. At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file.
  5. Below the commit message fields, decide whether to add your commit to the current branch or to a new branch. If your current branch is master, you should choose to create a new branch for your commit and then create a pull request.
  6. Click Propose file change.

More...

  1. Browse to the file in your repository that you want to delete.
  2. At the top of the file, click the 'Trash-bin'.
  3. At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file.
  4. Below the commit message fields, decide whether to add your commit to the current branch or to a new branch. If your current branch is master, you should choose to create a new branch for your commit and then create a pull request.
  5. Click Propose file change.


Send a pull request

See https://help.github.com/articles/about-pull-requests

Make changes

Just do the necessary changes.

Merge

See https://help.github.com/articles/merging-a-pull-request


Tidy up

See https://help.github.com/articles/deleting-and-restoring-branches-in-a-pull-request

See also

top

  • GitHub is the best place to share code with friends, co-workers, classmates, and complete strangers. Over eight million people use GitHub to build amazing things together.
  • Cloudforge, Free Git repository Website for all your code.

Tutorials

Reference

top

  1. Wikipedia Git-description, Git Software
  2. help-github, Setup.
  3. Roger Dudler, Sheet Cheat
  4. Help-GitHub Articles, Help-GitHub-Flow
  5. Guides-GitHub Flow Guides
  6. Help-GitHub Categories, Managing Files.