top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

GIT: What are commands used frequently in the git ?

+3 votes
607 views
GIT: What are commands used frequently in the git ?
posted Jan 14, 2016 by Harshita

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+3 votes

This isn't meant to be a comprehensive list of Git commands, just the ones we find ourselves using over and over again.

git add .
Called from the top-level directory of the repository.
Adds all updates (file modifications, new files, deletions) to the Git index, usually in preparation for a commit

git commit -v
Commits changes in the index to the branch. The "-v" (verbose) displays the changes going into the commit in diff format

git status
Displays changes in progress. These are updates that may or may not have been added but are definitely not committed.

git log
Lists all the commits for the current branch

git branch -a
Displays all the branches known to the local repository. This includes local and remote repository branches

git checkout [branch]
Checks out specified branch to the working tree (aka populates the repository directory structure with the appropriate version of files)

git checkout -f
Forces Git to re-checkout the current branch. This gets rid of modified files and added updates to the index. Useful if you've made changes that you don't want any more. Doesn't work for changes that you've already committed. Similar to
svn revert
in Subversion.

git pull
Pulls in changes based on the current branch's tracking setting. Fetches updated branch information from the tracked remote repository and merges the updates from the tracked remote branch

git push
Pushes changes to a remote repository based on the current branch's tracking settings. Pushes are made to the tracked remote repository.

FYI, by default Git will automatically update all branches on the remote repository that match the name of a local repository branch. You can override this by adding a "push" mapping in the remote repository's connection section in the local .git/config.

git push [remote] [local branch]:[remote branch]
Push up changes from the specified local branch to the specified remote branch on the remote repository.

This is required for new branches that don't exist on the remote. You'll also need to fully specify the remote branch with refs/heads/[remote branch].

git merge [branch]
Merges the changes from the specified branch to the current branch

git rebase [branch]
Resets the starting point of the current branch to the specified branch and reapplies all the updates that have been made

git config -l
Lists the configuration information for the repository. This includes remote connections and tracking information for branches

answer Jan 18, 2016 by Shivaranjini
0 votes

Tell Git who you are
1) Configure the author name and email address to be used with your commits.
git config --global user.name "Sam Smith"
.
2) Note that Git strips some characters (for example trailing periods) from user.name.
git config --global user.email sam@example.com
.
.
Create a new local repository
1) git init
.
.
Check out a repository
1) Create a working copy of a local repository:
git clone /path/to/repository
.
2) For a remote server, use:
git clone username@host:/path/to/repository
.
.
Add files
Add one or more files to staging (index):
git add
git add *
.
.
Commit
1) Commit changes to head (but not yet to the remote repository):
git commit -m "Commit message"
.
2) Commit any files you've added with git add, and also commit any files you've changed since then:
git commit -a
.
.
Push
1) Send changes to the master branch of your remote repository:
git push origin master
.
.
Status
1) List the files you've changed and those you still need to add or commit:
git status
.
.
Connect to a remote repository
1) If you haven't connected your local repository to a remote server, add the server to be able to push to it:
git remote add origin
.
2) List all currently configured remote repositories:
git remote -v
.
.
Branches
1) Create a new branch and switch to it:
git checkout -b
.
2) Switch from one branch to another:
git checkout
.
3) List all the branches in your repo, and also tell you what branch you're currently in:
git branch
.
4) Delete the feature branch:
git branch -d
.
5) Push the branch to your remote repository, so others can use it:
git push origin
.
6) Push all branches to your remote repository:
git push --all origin
.
7) Delete a branch on your remote repository:
git push origin :
.
.
Update from the remote repository
1) Fetch and merge changes on the remote server to your working directory:
git pull
.
2) To merge a different branch into your active branch:
git merge
.
3) View all the merge conflicts:
git diff
.
4) View the conflicts against the base file:
git diff --base
.
5) Preview changes, before merging:
git diff
.
6) After you have manually resolved any conflicts, you mark the changed file:
git add
.
.
Tags
1) You can use tagging to mark a significant changeset, such as a release:
git tag 1.0.0
.
2) CommitId is the leading characters of the changeset ID, up to 10, but must be unique. Get the ID using:
git log
.
3) Push all tags to remote repository:
git push --tags origin
.
.
Undo local changes
1) If you mess up, you can replace the changes in your working tree with the last content in head:
Changes already added to the index, as well as new files, will be kept.
git checkout --
.
2) Instead, to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it, do this:
git fetch origin
git reset --hard origin/master
.
.
Search
Search the working directory for foo(): git grep "foo()"

answer Jan 18, 2016 by Vikas Upadhyay
Similar Questions
0 votes

I'm new to git, and having done a fair bit of reading up I've set up a github account ready to get started.

I plan to combine elements of Inuit CSS (https://github.com/csswizardry/inuit.css ) with Bones (https://github.com/eddiemachado/bones ) to create my own starter framework for Wordpress projects.

My question is should I fork each of these projects and clone them locally, then edit/combine and upload to a new repository? The help info regarding forking appears to imply that you would fork a repository when you were looking to contribute to the original repository rather than create a derivative work, or perhaps that is just the most common use case?

The other option I can see is to just download the repository for each as a zip file, combine/edit and then upload them to a new repository.

Is there a benefit to either route or perhaps another approach that I might be missing?

+1 vote

I was learning to user git-bash and github. As part of tutorial we were asked to set username & password through git-bash command line and create an account in github. But since I already set the email through gitbash global config, I am not allowed to create account or create a password for my account .

Please let me know how can I create a account in github or delete the entry to start fresh.

...