Git Commands


1.Download git for Mac
https://sourceforge.net/projects/git-osx-installer/files/
or
brew install git
2.For git version:
git --version
3.Configure Git username and email:
$ git config --global user.name <username>
$ git config --global user.email <emailid>
Define the author name to be used for all commits in the current repository. Typically, you’ll want to use the --global flag to set configuration options for the current user.
4.SourceTree, a free visual Git client for Mac, comes with its own bundled version of Git
https://www.sourcetreeapp.com/
6. git init
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.
cd into your project folder and run git init, and you’ll have a fully functional Git repository.
However, git init only needs to be executed once to create a central repository—developers typically don't use git init to create their local repositories. Instead, they'll usually use git clone to copy an existing repository onto their local machine.
7. git clone <repo>
The git clone command copies an existing Git repository.
git clone <repo> <directory>
Clone the repository located at <repo> into the folder called <directory> on the local machine.
If a project has already been set up in a central repository, the git clone command is the most common way for users to obtain a development copy. Like git init, cloning is generally a one-time operation—once a developer has obtained a working copy, all version control operations and collaborations are managed through their local repository.
8.git status to view the state of the working directory and the staging area.
9. git add
The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. However, git add doesn't really affect the repository in any significant way—changes are not actually recorded until you run git commit.
git add .
git add <file>
git add <directory>
Developing a project revolves around the basic edit/stage/commit pattern. First, you edit your files in the working directory. When you’re ready to save a copy of the current state of the project, you stage changes with git add. After you’re happy with the staged snapshot, you commit it to the project history with git commit.
10.git commit
git commit -m "<message>"
git commit -a Commit a snapshot of all changes in the working directory.
11. git stash command takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy.
12. git stash pop Popping your stash removes the changes from your stash and reapplies them to your working copy.
Alternatively, you can reapply the changes to your working copy andkeep them in your stash with git stash apply
13. git checkout
The git checkout command serves three distinct functions: checking out files, checking out commits, and checking out branches.
git checkout <branch name>
14. git fetch
The git fetch command imports commits from a remote repository into your local repo. The resulting commits are stored as remote branches instead of the normal local branches that we’ve been working with. This gives you a chance to review changes before integrating them into your copy of the project.
15. git pull - It’s an easy way to synchronize your local repository with upstream changes.
16. git push is to publish your local changes to a central repository.
git push <remote> <branch>
17. git branch
The git branch command lets you create, list, rename, and delete branches.
git branch <branch> Create a new branch called <branch>. This does not check out the new branch.
git branch -d <branch> Delete the specified branch. This is a “safe” operation in that Git prevents you from deleting the branch if it has unmerged changes.
git branch -D <branch> Force delete the specified branch, even if it has unmerged changes.
git branch -m <branch> Rename the current branch to <branch>.
18. git merge
The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch.
git merge <branch>
Apart from run these commands either in terminal or command prompt, we can also do it in directly in github site.

Comments

Popular posts from this blog

GitHub Administration