Coder Social home page Coder Social logo

git-tutorial's Introduction

Git-tutorial

Sources:

Git configuration

Set the name that will be attached to your commits and tags.

git config --global user.name "Your Name"

Set the e-mail address that will be attached to your commits and tags.

git config --global user.email "[email protected]"

Starting A Project

Create a new local repository.

git init [project name]

Downloads a project with the entire history from the remote repository.

$ git clone [project url]

When you clone a repository with git clone, it automatically creates a remote connection called origin pointing back to the cloned repository.

Day-To-Day Work

Displays the status of your working directory.

git status

Add a file to the staging area.

git add [file]

Show changes between working directory and staging area.

git diff [file]

Shows any changes between the staging area and the repository.

git diff --staged [file]

Discard changes in working directory. This operation is unrecoverable.

git checkout -- [file]

Revert your repository to a previous known working state.

git reset [file]

Create a new commit from changes added to the staging area.

git commit -m [message]

Remove file from working directory and staging area.

git rm [file]

Git branching

List all local branches in repository. With -a: show all branches (with remote).

git branch [-a]

Create new branch, referencing the current HEAD.

git branch [branch_name]

Rename branch

git branch -m [old_name][new_name]

Both Conservancy and the Git project are aware that the initial branch name, ‘master’, is offensive to some people. Many communities, both on GitHub and in the wider Git community, are considering renaming the default branch name of their repository from master. GitHub is gradually renaming the default branch of our own repositories from master to main.

Switch working directory to the specified branch. With -b: Git will create the specified branch if it does not exist.

git checkout [-b][branch_name]

Join specified [from name] branch into your current branch.

git merge [-m][from name]

Git Remote

List the remote connections you have to other repositories. -v include the URL of each connection.

git remote [-v]

Create a new connection to a remote repository. After adding a remote, you’ll be able to use [name] as a convenient shortcut for [url] in other Git commands.

git remote add [name] [URL]

Two of the easiest ways to access a remote repo are via the HTTP and the SSH protocols. HTTP is an easy way to allow anonymous, read-only access to a repository. But, it’s generally not possible to push commits to an HTTP address. For read-write access, you should use SSH instead.

Remove the connection to the remote repository called [name].

git remote remove [name]

Change your remote's URL

git remote set-url [remote] [url]

Fetch changes from the remote, but not update tracking branches.

git fetch [remote]

Fetch changes from the remote and merge current branch with its upstream.

git pull [remote] [branch]

Push local branch to remote repository.

git push -u [remote] [branch]

Reverting changes

Switches the current branch to the target reference, leaving a difference as an uncommitted change. When --hard is used, all changes are discarded.

git reset [--hard] [target reference]

Create a new commit, reverting changes from the specified commit.

git revert [commit sha]

Review your work

List commit history of current branch.

git log

List operations made on local repository

git reflog

git-tutorial's People

Contributors

demelomatt avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.