How to Log in Again to Git Cmd

this guide is a Git toolbox

Working with Git on the command line can be daunting. To help with that, nosotros've put together a list of mutual Git commands, what each 1 means, and how to utilize them. Our hope is that this makes Git easier to apply on a daily basis.

Git has many great clients that permit yous to utilise Git without the command line. Knowing what actions the client is performing in the background is beneficial to understanding how Git works. If y'all're getting started with Git also check out our fantastic guide on the topic.

Working with local repositories

git init

This control turns a directory into an empty Git repository. This is the first stride in creating a repository. After running git init, adding and committing files/directories is possible.

Usage:

          # alter directory to codebase $ cd /file/path/to/code  # make directory a git repository $ git init        

In Practice:

          # alter directory to codebase $ cd /Users/computer-name/Documents/website  # brand directory a git repository $ git init Initialized empty Git repository in /Users/figurer-name/Documents/website/.git/        

git add

Adds files in the to the staging area for Git. Before a file is bachelor to commit to a repository, the file needs to be added to the Git index (staging area). There are a few different means to use git add, by adding entire directories, specific files, or all unstaged files.

Usage:

          $ git add <file or directory name>        

In Practice:

          # To add all files not staged: $ git add .  # To phase a specific file: $ git add alphabetize.html  # To stage an entire directory: $ git add css        

git commit

Tape the changes made to the files to a local repository. For like shooting fish in a barrel reference, each commit has a unique ID.

It's best practise to include a bulletin with each commit explaining the changes made in a commit. Adding a commit message helps to find a particular change or agreement the changes.

Usage:

          # Adding a commit with message $ git commit -k "Commit message in quotes"        

In Practice:

          $ git commit -grand "My first commit message" [SecretTesting 0254c3d] My commencement commit message ane file changed, 0 insertions(+), 0 deletions(-) create mode 100644 homepage/index.html        

git status

This command returns the current state of the repository.

git condition will return the current working branch. If a file is in the staging expanse, merely not committed, it shows with git condition. Or, if at that place are no changes it'll render zippo to commit, working directory clean.

Usage:

          $ git status        

In Practice:

          # Message when files have not been staged (git add) $ git status On co-operative SecretTesting Untracked files:   (use "git add <file>..." to include in what will be committed)            homepage/index.html            # Message when files have been non been committed (git commit) $ git status On branch SecretTesting Your branch is upwardly-to-date with 'origin/SecretTesting'. Changes to be committed:   (use "git reset HEAD <file>..." to unstage)            new file:   homepage/index.html            # Bulletin when all files have been staged and committed  $ git status On co-operative SecretTesting cipher to commit, working directory clean        

git config

With Git, in that location are many configurations and settings possible. git config is how to assign these settings. Two important settings are user user.name and user.email. These values set up what email address and name commits will be from on a local computer. With git config, a --global flag is used to write the settings to all repositories on a computer. Without a --global flag settings will only apply to the electric current repository that you are currently in.

In that location are many other variables available to edit in git config. From editing color outputs to changing the beliefs of git status. Learn about git config settings in the official Git documentation.

Usage:

          $ git config <setting> <command>        

In Practice:

          # Running git config globally $ git config --global user.email "my@emailaddress.com" $ git config --global user.name "Brian Kerr"  # Running git config on the electric current repository settings $ git config user.email "my@emailaddress.com" $ git config user.name "Brian Kerr"        

git branch

To decide what branch the local repository is on, add a new co-operative, or delete a branch.

Usage:

          # Create a new branch $ git branch <branch_name>  # List all remote or local branches $ git branch -a  # Delete a branch $ git branch -d <branch_name>        

In Practice:

          # Create a new branch $ git branch new_feature  # Listing branches $ git branch -a *            SecretTesting            new_feature   remotes/origin/stable   remotes/origin/staging   remotes/origin/master -> origin/SecretTesting    # Delete a co-operative $ git branch -d new_feature Deleted branch new_feature (was 0254c3d).        

git checkout

To get-go working in a dissimilar branch, use git checkout to switch branches.

Usage:

          # Checkout an existing branch $ git checkout <branch_name>  # Checkout and create a new branch with that proper name $ git checkout -b <new_branch>        

In Exercise:

          # Switching to branch 'new_feature' $ git checkout new_feature Switched to branch 'new_feature'  # Creating and switching to branch 'staging' $ git checkout -b staging Switched to a new branch 'staging'        

git merge

Integrate branches together. git merge combines the changes from one branch to another branch. For instance, merge the changes made in a staging co-operative into the stable branch.

Usage:

          # Merge changes into current branch $ git merge <branch_name>        

In Exercise:

          # Merge changes into current branch $ git merge new_feature Updating 0254c3d..4c0f37c Fast-forrard  homepage/index.html | 297            ++++++++++++++++++++++++++++++++++++++++++++++++++++++++            1 file changed, 297 insertions(+)  create mode 100644 homepage/index.html        

Working with remote repositories

git remote

To connect a local repository with a remote repository. A remote repository can have a name set to avert having to remember the URL of the repository.

Usage:

          # Add remote repository $ git remote <control> <remote_name> <remote_URL>  # List named remote repositories $ git remote -v        

In Practice:

          # Adding a remote repository with the name of beanstalk $ git remote add origin git@account_name.git.beanstalkapp.com:/acccount_name/repository_name.git  # List named remote repositories $ git remote -5 origin git@account_name.git.beanstalkapp.com:/acccount_name/repository_name.git (fetch) origin git@account_name.git.beanstalkapp.com:/acccount_name/repository_name.git (push)        

Annotation: A remote repository can have whatsoever name. It's common practice to name the remote repository 'origin'.

git clone

To create a local working copy of an existing remote repository, use git clone to copy and download the repository to a computer. Cloning is the equivalent of git init when working with a remote repository. Git volition create a directory locally with all files and repository history.

Usage:

          $ git clone <remote_URL>        

In Practice:

          $ git clone git@account_name.git.beanstalkapp.com:/acccount_name/repository_name.git Cloning into 'repository_name'... remote: Counting objects: 5, done. remote: Compressing objects: 100% (iii/3), done. remote: Total 5 (delta 0), reused 0 (delta 0) Receiving objects: 100% (5/5), iii.08 KiB | 0 bytes/s, washed. Checking connectivity... washed.        

git pull

To get the latest version of a repository run git pull. This pulls the changes from the remote repository to the local computer.

Usage:

          $ git pull <branch_name> <remote_URL/remote_name>        

In Practice:

          # Pull from named remote $ git pull origin staging From account_name.git.beanstalkapp.com:/account_name/repository_name  * branch            staging    -> FETCH_HEAD  * [new co-operative]      staging    -> origin/staging Already up-to-date.  # Pull from URL (non ofttimes used) $ git pull git@account_name.git.beanstalkapp.com:/acccount_name/repository_name.git staging From account_name.git.beanstalkapp.com:/account_name/repository_name  * co-operative            staging    -> FETCH_HEAD  * [new co-operative]      staging    -> origin/staging Already upwardly-to-engagement.        

git push button

Sends local commits to the remote repository. git push requires 2 parameters: the remote repository and the co-operative that the push is for.

Usage:

          $ git push <remote_URL/remote_name> <co-operative>  # Push all local branches to remote repository $ git push —all        

In Practice:

          # Button a specific co-operative to a remote with named remote $ git push origin staging Counting objects: v, done. Delta compression using up to iv threads. Compressing objects: 100% (iii/3), done. Writing objects: 100% (v/v), 734 bytes | 0 bytes/southward, done. Total five (delta two), reused 0 (delta 0) To git@account_name.git.beanstalkapp.com:/acccount_name/repository_name.git    ad189cb..0254c3d  SecretTesting -> SecretTesting  # Push all local branches to remote repository $ git button --all Counting objects: iv, done. Delta compression using upward to 4 threads. Compressing objects: 100% (4/4), washed. Writing objects: 100% (4/iv), 373 bytes | 0 bytes/s, washed. Full 4 (delta two), reused 0 (delta 0) remote: Resolving deltas: 100% (ii/two), completed with 2 local objects. To git@account_name.git.beanstalkapp.com:/acccount_name/repository_name.git    0d56917..948ac97  master -> master    ad189cb..0254c3d  SecretTesting -> SecretTesting        

Advanced Git Commands

git stash

To save changes fabricated when they're not in a land to commit them to a repository. This volition shop the work and requite a make clean working directory. For instance, when working on a new feature that's not complete, but an urgent bug needs attending.

Usage:

          # Store electric current work with untracked files $ git stash -u  # Bring stashed work back to the working directory $ git stash pop        

In Practice:

          # Shop current piece of work $ git stash -u Saved working directory and index land WIP on SecretTesting: 4c0f37c Adding new file to co-operative Caput is now at 4c0f37c Calculation new file to co-operative  # Bring stashed piece of work back to the working directory $ git stash pop On branch SecretTesting Your branch and 'origin/SecretTesting' have diverged, and take one and 1 dissimilar commit each, respectively.   (utilize "git pull" to merge the remote branch into yours) Changes not staged for commit:   (employ "git add <file>..." to update what will be committed)   (employ "git checkout -- <file>..." to discard changes in working directory)            modified:   index.html            no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/stash@{0} (3561897724c1f448ae001edf3ef57415778755ec)        

git log

To show the chronological commit history for a repository. This helps give context and history for a repository. git log is available immediately on a recently cloned repository to see history.

Usage:

          # Show entire git log $ git log  # Show git log with date pameters $ git log --<subsequently/before/since/until>=<date>  # Show git log based on commit author $ git log --<author>="Author Name"                  

In Practice:

          # Evidence unabridged git log $ git log            commit 4c0f37c711623d20fc60b9cbcf393d515945952f            Author: Brian Kerr <my@emailaddress.com> Engagement:   Tue Oct 25 17:46:eleven 2016 -0500      Updating the diction of the homepage footer            commit 0254c3da3add4ebe9d7e1f2e76f015a209e1ef67            Author: Ashley Harpp <my@emailaddress.com> Date:   Wed Oct 19 16:27:27 2016 -0500      My first commit message  # Show git log with date pameters $ git log --before="Oct xx"            commit 0254c3da3add4ebe9d7e1f2e76f015a209e1ef67            Author: Ashley Harpp <my@emailaddress.com> Appointment:   Wed October nineteen sixteen:27:27 2016 -0500      My first commit message  # Show git log based on commit author $ git log --writer="Brian Kerr"            commit 4c0f37c711623d20fc60b9cbcf393d515945952f            Author: Brian Kerr <my@emailaddress.com> Engagement:   Tue Oct 25 17:46:11 2016 -0500      Updating the wording of the homepage footer                  

git rm

Remove files or directories from the working index (staging expanse). With git rm, there are ii options to proceed in mind: strength and cached. Running the command with force deletes the file. The cached command removes the file from the working index. When removing an unabridged directory, a recursive command is necessary.

Usage:

          # To remove a file from the working index (cached): $ git rm --buried <file proper noun>  # To delete a file (strength): $ git rm -f <file proper noun>  # To remove an entire directory from the working alphabetize (cached): $ git rm -r --cached <directory proper name>  # To delete an entire directory (forcefulness): $ git rm -r -f <file name>        

In Practice:

          # To remove a file from the working alphabetize: $ git rm --cached css/mode.css rm 'css/style.css'  # To delete a file (force): $ git rm -f css/way.css rm 'css/manner.css'  # To remove an entire directory from the working index (cached): $ git rm -r --buried css/ rm 'css/style.css' rm 'css/style.min.css'  # To delete an entire directory (force): $ git rm -r -f css/ rm 'css/fashion.css' rm 'css/fashion.min.css'                  

More than Git Resources

Gear up to acquire more about Git and it'due south dissimilar commands? There are countless articles and sites on Git, here are some of our favorites:

  • The official Git site
  • Git reference
  • Git for the lazy
  • Pro Git (Volume)
  • Writing meaningful commit letters
  • Git from the inside out

johnsondivid1940.blogspot.com

Source: http://guides.beanstalkapp.com/version-control/common-git-commands.html

0 Response to "How to Log in Again to Git Cmd"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel