How to clone, commit, push git repository
If you are working with Git and want to edit any files in git repository, then you need to follow the following steps
Go to the local directory where you wants to copy the git repo.
$ cd directory
$ git clone <repo>
$ git clone <repo> <directory>
Clone the repository located at <repo> into the folder called <directory> on the local machine.
To update the git repository
$ git pull
How to recursively add the files in directory
Go to the directory where your files are located.
$ cd directory
$ mkdir -p /dir1/dir2/dir3/dir4/
$ touch new file $ git add *
Now you must commit these changes (You can give necessary comments)
$ git commit -m "Adding new files"
If you want to add a directory and all the files which are located inside it recursively, Go to the directory where the directory you want to add is located.
$ cd directory $ git add directoryname
Now you must commit these changes (You can give necessary comments)
$ git commit -m "Adding a new directory"
Note that the above step will commit recursively the subdirectories and files present in the directory.
Finally push the changes to git server repo
$ git push -u origin masterHow do I show or change my Git username (or email address)?
There are several ways to show your Git username
git config user.name
You can also use
git config --list
which returns this output:
user.name=GitLab
user.email=(none)
core.autocrlf=input
Finally, you can also see your Git username in the Git configuration file in your HOME directory on Unix systems, i.e., this file:
~/.gitconfig
How to change your Git email address
git config user.email
And you can change your Git email address like this:
git config --global user.email [your email address here]
Set git email address on a per repository basis
Keeping global email address for all repositories is not a good idea, especially ifthere are multiple users using the same or repositories.Git allows you to specify email addresses on a per repository basis. This ishandy when working with repositories from different environmentSet the global user email as belowemail = "(none)"When in the repo directory, use the following commands to set a per repository email address:adixit@hostname:~/git$ git config user.name “amit dixit” adixit@hostname:~/git$ git config user.email “some@gittestdomain.com”Alternatively, you can edit .git/config manually, and add the required information under the [user] heading:[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = https://adixit@git.dev.somedomain.com/repo/gitrepo/new.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [user] email = some@gittestdomain.comThe benefit of keeping global email as none is that if anytime you forget to change the user email per repository and once you try to commit, you’ll get the following error message:*** Please tell me who you are. Run git config --global user.email "you@example.com" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. fatal: unable to auto-detect email address (got '(none)')
No comments:
Post a Comment