- Details
- Category: Git
- Hits: 928
- Open a command prompt.
-
To launch GitHub Desktop to the last opened repository, type
github
. To launch GitHub Desktop for a particular repository, use thegithub
command followed by the path to the repository.C:\Users\octocat> github path\to\repo
You can also change to your repository path and type
github
followed by a period.C:\Users\octocat> cd repo\myrepo C:\Users\octocat\repo\myrepo> github .
- Details
- Category: Git
- Hits: 8328
Create an empty directory: directoryname
$ mkdir directoryname
$ cd directoryname
Create a directoryname.html file in it
$ touch directoryname.html
Create a repository
$ git init
Add the page to the repository
$ git add directoryname.html
$ git commit -m "First Commit to directoryname"
Check the status of the repository
$ git status
Changing the “directoryname.html” page
$ start notepad++ directoryname.html
Check the working directory’s status.
$ git status
Adding changes
$ git add directoryname.html
$ git status
Staging and committing
$ git add directoryname.html
$ git commit -m "Changes directoryname.html <h1>Hello, World!</h1>"
Commiting the changes
$ git commit
# your editor opens
# On the first line, enter the comment: “Added hi tag”.
$ git commit
Checking the status
$ git status
# The working directory is clean, you can continue working.
Change the “directoryname.html” page so that it contained default tags <html> and <body>.
$ start notepad++ directoryname.html
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>
$ git add directoryname.html
Now add the HTML headers (<head> section) to the “directoryname.html” page.
$ start notepad++ directoryname.html
<html>
<head>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
$ git status
Commit
Commit the staged changes (default values), then check the status one more time.
$ git commit -m "Added standard HTML page tags"
$ git status
Adding the second change
$ git add .
$ git status
Commit the second change
$ git commit -m "Added HTML header"
History: Getting a list of changes made is a function
$ git log
One line history
$ git log --pretty=oneline
Options to choose which entreis appear in the log.
git log --pretty=oneline --max-count=2
git log --pretty=oneline --since=20.minutes-ago
git log --pretty=oneline --until=5.minutes-ago
git log --pretty=oneline --author=<your name>
git log --pretty=oneline --all
git log --pretty=oneline --since=20.minutes-ago
git log --pretty=oneline --until=5.minutes-ago
Getting fancy
$ git log --all --pretty=format:"%h %cd %s (%an)" --since='7.days-ago'
- Details
- Category: Git
- Hits: 7085
Git Cheat Sheet 1
Check Setting
$ git config --global --list
# If you want to check your global settings
$ git config --list
# If you want to check your local repository
User Name
$ git config user.name "John Doe"
# set your username for a specific repository
$ git config --global user.name "John Doe"
# global set your username for every repository on your computer:
$ git config user.name
# Confirm that you have set your username correctly
User Email
$ git config user.email
#Setting your email address for a single repository.
$ git config user.email
# Confirm that you have set your email address correctly
$ git config --global user.email "
# Setting your email address for every repository on your computer
$ git config --global user.email
# Confirm that you have set your email address correctly
Getting Help
$ git help config
# Displays git-config(1) Manual Page. Launching default browser to display HTML ...
$ git help git
# Display the git[1] Manual Page. Launching default browser to display HTML ...
$ git help --help
# Display the git-help(1) Manual Page . Launching default browser to display HTML
$ git help log
# Display git-log(1) Manual Page. Launching default browser to display HTML ...
Modify some files
$ git add yourfile.txt
# Modify some files, then add their updated contents to the index: (Open and Modifty yourfile.txt file than save yourfile.txt file)
git diff --cached
$ git diff --cached
# see what is about to be committed using git diff with the --cached option
git commit
$ git commit
# Record changes to the repository, to actually record the snapshot.
git commit -a
$ git commit -a
# automatically stage all tracked, modified files before the commit
- Details
- Category: Git
- Hits: 6945
Git Cheat Sheet 2
Check the status of the repository
$ git status
# Check the status of the repository, to see what the state of our project is.
Create a Directory
$ mkdir my_git_project
# create a directory where we’ll store the files for our project:
Changes Directory
$ cd my_git_project
# changes the active directory to the newly created one
Initializes a git repository
$ git init
# Initializes a git repository – creates the initial ‘.git’ directory in a new or in an existing project.
The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new empty repository. Most of the other Git commands are not available outside of an initialized repository, so this is usually the first command you’ll run in a new project.
Creates an empty Git repository - basically a .git directory with subdirectories for objects, refs/heads, refs/tags, and template files. An initial HEAD file that references the HEAD of the master branch is also created.
Show file in working tree
$ git ls-files
# Show information about files in the index and the working tree
History of the project
$ git log
# The history shows the list of commits, each with a unique hash, an author, a timestamp and a commit message.
Synchronize it with the remote repository
$ git remote add origin https://github.com/yourgitname/my_git_project.git
$ git push -u origin master
# synchronize it with the remote repository:
- Details
- Category: Git
- Hits: 6907
Git Cheat Sheet 3
Branch
$ git branch
# To see the list of branches and the current branch you're working on
See the remote branches
$ git branch -a
# You can see the remote branches too postfix -a
Create a Branch
$ git branch test_branch
# To create a new branch and stay in your current branch
To change the active branch
$ git checkout test_branch
#To change the active branch, we can run the checkout command
Create and checkout to a new branch in a single command
$ git checkout -b new_test_branch
# create and checkout to a new branch in a single command by postfixing -b to the checkout command:
To rename the current branch
$ git branch -m renamed_branch
# Run the command to rename the current branch to renamed_branch.
Delete a branch, run the following command:
$ git branch -D new_test_branch
# The -D option used above deletes a branch
- Retrieved from GitHowTo
The ultimate format of the log
Retrieved from https://githowto.com/history
$ git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
Let’s look at it in detail:
--pretty="..." defines the output format.
%h is the abbreviated hash of the commit
%d commit decorations (e.g. branch heads or tags)
%ad is the commit date
%s is the comment
%an is the name of the author
--graph tells git to display the commit tree in the form of an ASCII graph layout
--date=short keeps the date format short and nice