Last active
November 17, 2015 11:50
-
-
Save Varnan/0aca92af407caafa642d to your computer and use it in GitHub Desktop.
Git Basic Opertaions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=========================== GIT REPOSITORY ==================================== | |
https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-init | |
Start from the beginning, because we need to initialize the git empty repository for our project. | |
$ git init - if encountered any error for git , just install, | |
$ sudo apt-get install git | |
Our git repository must be in project path, then only the other command will work. | |
If want to remove already created git. | |
$ rm -rf .git | |
======================== Command line instructions ================= | |
######## Git global setup ############ | |
$ git config --global user.name "GIT NAME" | |
Eg: $ git config --global user.name "Varnan" | |
$ git config --global user.email "GIT EMAIL" | |
Eg: $ git config --global user.email "[email protected]" | |
######## Create a new repository ################################## | |
git clone [email protected]:varnan/TEST.git | |
cd TEST | |
touch README.md | |
git add README.md | |
git commit -m "add README" | |
git push -u origin master | |
######## Existing folder or Git repository ######################## | |
cd existing_folder | |
$ git init | |
$ git remote add origin [email protected]:varnan/TEST.git | |
$ git add * | |
$ git commit -m "First Commit" | |
$ git push -u origin master | |
######## Clone a specified branch to New Folder ######################## | |
$ git clone "GIT SSH" -b "BRANCH NAME" | |
Eg: $ git clone [email protected]:varnan/TEST.git -b developer | |
######## Some basic commands ########################################### | |
$ git status - To check the repo status. | |
$ git add . Or git add <file-path> - To add files to repo. | |
$ git commit -m <msg> - To commit changes with log message what you have done in this commit. | |
$ git push origin <branch> - To push the committed changes to repo. | |
$ git checkout <existing-branch> - To checkout or get desired branch to work. | |
$ git checkout -b <new-branch> - To create new branch and checkout it also to work. | |
$ git pull (or) git pull origin <existing-branch> - Pull changes from specified repo. | |
$ git ls-files --deleted -z | xargs -0 git rm - Make the deleted changes | |
The following commands are useful in the Git branch workflow. | |
git branch: Lists all a Git project's branches. | |
git branch branch_name: Creates a new branch. | |
git checkout branch_name: Used to switch from one branch to another. | |
git merge branch_name: Used to join file changes from one branch to another. | |
git branch -d branch_name: Deletes the branch specified. | |
git clone: Creates a local copy of a remote. | |
git remote -v: Lists a Git project's remotes. | |
git fetch: Fetches work from the remote into the local copy. | |
git merge origin/master: Merges origin/master into your local branch. | |
git push origin <branch_name>: Pushes a local branch to the origin remote. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment